pub fn db_into(
slice: &mut [DepreciationPeriod],
cost: Decimal,
salvage: Decimal,
factor: Option<Decimal>,
round: Option<(u32, RoundingStrategy)>,
)
Expand description
Declining Balance Depreciation (DB) Into
Calculates the depreciation schedule for an asset using the declining balance method given a declining balance factor (e.g. double-declining balance), mutating a “slice” of DepreciationPeriod.
§Arguments
slice
- A mutable slice ofDepreciationPeriod
instances to be filled with the depreciation schedule.
Warning: The length of the slice should be as long as the life as the asset or there will be unexpected behavior.
cost
- The initial cost of the assertsalvage
- The estimated salvage value of the asset at the end of its useful lifefactor
(optional) - The factor by which the straight-line depreciation rate is multiplied (default is 2 for double-declining balance)round
(optional) - A tuple specifying the number of decimal places and a rounding strategy for the amounts(dp, RoundingStrategy)
, default is no rounding of calculations. The final depreciation expense is adjusted to ensure the remaining book value is equal to the salvage value.rust_decimal::RoundingStrategy::MidpointNearestEven
(“Bankers Rounding”) is likely what you are looking for as the rounding strategy.
If rounding is enabled, the final period will be adjusted to “zero” out the remaining book value to the salvage value.
§Examples
- $10,000 asset, $1,000 salvage value, 5 year life
use rust_finprim::amort_dep_tax::{DepreciationPeriod, db_into};
use rust_decimal_macros::*;
let life = 5;
let cost = dec!(10_000);
let salvage = dec!(1_000);
let mut schedule = vec![DepreciationPeriod::default(); life as usize];
db_into(&mut schedule, cost, salvage, None, None);