Skip to content

fix(eval): truncate DDB period to integer, matching Excel behavior#37

Open
TyrGo wants to merge 1 commit intoPSU3D0:mainfrom
TyrGo:fix/ddb-fractional-period
Open

fix(eval): truncate DDB period to integer, matching Excel behavior#37
TyrGo wants to merge 1 commit intoPSU3D0:mainfrom
TyrGo:fix/ddb-fractional-period

Conversation

@TyrGo
Copy link
Copy Markdown

@TyrGo TyrGo commented Mar 24, 2026

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).

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 period to 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.

@TyrGo TyrGo force-pushed the fix/ddb-fractional-period branch from a883ce8 to f6d9eaa Compare March 24, 2026 18:49
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).
@TyrGo TyrGo force-pushed the fix/ddb-fractional-period branch from f6d9eaa to 2eef331 Compare March 25, 2026 00:37
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