[英]calculate straight line declining
我今年的資產(例如車輛)價值為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]
]
任何幫助,將不勝感激...謝謝你。
從assetCurrentBookValue - assetYearlyDepreciation
和new 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])
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.