fix(eval): truncate DDB period to integer, matching Excel behavior#37
Open
TyrGo wants to merge 1 commit intoPSU3D0:mainfrom
Open
fix(eval): truncate DDB period to integer, matching Excel behavior#37TyrGo wants to merge 1 commit intoPSU3D0:mainfrom
TyrGo wants to merge 1 commit intoPSU3D0:mainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR fixes the DDB depreciation function to truncate fractional period inputs to an integer before validation and calculation, matching Excel behavior and aligning with how the existing DB implementation handles period iteration.
Changes:
- Truncate
periodto an integer prior to bounds checking and the depreciation loop. - Remove the prior fractional-period weighted blending logic.
- Add JSON formula tests covering integer, fractional, and error-case periods, plus a custom factor case.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| tests/formula_tests/financial.json | Adds coverage for DDB across multiple periods, fractional truncation cases, and #NUM! error scenarios. |
| crates/formualizer-eval/src/builtins/financial/depreciation.rs | Updates DDB implementation to use integer-truncated period, removes fractional blending, and refreshes docs/examples/FAQ accordingly. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
a883ce8 to
f6d9eaa
Compare
The DDB function applied an incorrect weighted-average blending for fractional period values. Excel (and the sibling DB function in this codebase) truncates the period argument to an integer before calculating depreciation. Changes: - Truncate period to integer before the depreciation loop, consistent with DB and Excel behavior. - Move the period bounds check after truncation so that fractional values like 5.9 (which truncate to 5) are accepted when life=5, while sub-unit values like 0.5 (which truncate to 0) correctly return #NUM!. - Remove the incorrect fractional-period blending block and its TODO. - Update docstring to document truncation behavior and add FAQ entry. - Add inline example for fractional period truncation. - Add 10 JSON formula tests covering: second period, final period with salvage floor, fractional periods (0.5, 1.9, 2.5, 5.9), custom factor, and error cases (period=0, period>life, negative period).
f6d9eaa to
2eef331
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The DDB function applied an incorrect weighted-average blending for fractional period values. Excel (and the sibling DB function in this codebase) truncates the period argument to an integer before calculating depreciation.
Changes: