Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix rounding error in depreciation value using decimal arithmetic #3

Merged
merged 1 commit into from
Feb 23, 2022

Conversation

ankurdave
Copy link
Contributor

What changes were proposed in this pull request?

This plugin currently converts start and end values from Decimal to float before doing any calculations. float is appropriate for generating the depreciation curves, but not for calculating the depreciation values that will go into the ledger. As a result, for many choices of start value, floating-point error causes this plugin to produce unbalanced transactions like the following:

2020-04-30 * "Test-auto_depreciation:Nikon"
  Assets:Fixed-Assets                               -3 LENS {999.95 CNY, 2020-03-31, "Nikon"}
  Assets:Fixed-Assets                                3 LENS {559 CNY, 2020-04-30, "Nikon"}
  Expenses:Depreciation  1322.850000000000136424205266 CNY

The fix is to keep the start and end values as Decimals except when generating the depreciation curves.

How was this patch tested?

Added an end-to-end test called test_rounding_errors() that previously failed and now passes.

@hktkzyx
Copy link
Owner

hktkzyx commented Feb 23, 2022

Thanks for your PR so much! I will merge your commit very soon.

@hktkzyx hktkzyx merged commit 1a576f1 into hktkzyx:master Feb 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants