【问题标题】:calculate straight line declining计算直线下降
【发布时间】:2016-11-01 20:33:33
【问题描述】:

我今年拥有价值 1000 元的资产(比如车辆)...

var assetCurrentBookValue = 1000

车辆将在 5 年内贬值...这意味着未来 5 年内价值将变为 0...

var assetLife = 5

每年折旧变成...

var assetYearlyDepreciation = assetCurrentBookValue / assetLife

我需要像这样计算年折旧后的年价值...

year    assetYearlyDepreciation         assetBookVaue
2016    200                                     1000
2017    200                                     800
2018    200                                     600
2019    200                                     400
2020    200                                     200
2021    200                                     0

我需要像这样转换成数组...

[
    [2016,1000],
    [2017,800],
    [2018,600],
    [2019,400],
    [2020,200],
    [2021,0]
]

这是我的解决方法...

var index = Array.from(Array(assetLife).keys());
var thisYear = new Date().getFullYear()

var assetYearlyBookValue = [[thisYear,assetCurrentBookValue]]

index.forEach((o) => {
    assetYearlyBookValue.push([o + thisYear + 1, assetCurrentBookValue - assetYearlyDepreciation])
});

但我得到了..

[
    [2016,1000],
    [2017,800],
    [2018,800],
    [2019,800],
    [2020,800],
    [2021,800]
]

任何帮助将不胜感激...谢谢您..

【问题讨论】:

  • 真的不清楚你想用这段代码做什么。 assetEconomicLife 是什么?
  • 错字.. 应该是assetLife

标签: javascript accounting


【解决方案1】:

assetCurrentBookValue - assetYearlyDepreciationnew Date().getFullYear() 修改您的结果并将它们存储到变量中,以便您可以获得不断变化的结果:

var index = Array.from(Array(assetEconomicLife).keys());
var thisYear = new Date().getFullYear()

var assetYearlyBookValue = [[thisYear,assetCurrentBookValue]]
var lastRes = assetCurrentBookValue

index.forEach((o) => {
    lastRes -= assetYearlyDepreciation
    assetYearlyBookValue.push([o + (++thisYear), lastRes])
});

【讨论】:

    猜你喜欢
    • 2021-08-13
    • 1970-01-01
    • 1970-01-01
    • 2011-09-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多