Skip to content

Tidy up conversion and creation for 2.0 - #30

Merged
dereuromark merged 1 commit into
nextfrom
feature/api-tidy
Oct 11, 2026
Merged

dereuromark merged 1 commit into
nextfrom
feature/api-tidy

Conversation

@dereuromark

Copy link
Copy Markdown
Contributor

Five API changes for 2.0, all on the conversion and creation side.

  • toInt() no longer drops decimals on its own. A value with decimals other than zero throws a RoundingNecessaryException unless a rounding mode is passed: toInt(Decimal::ROUND_DOWN) gives the 1.x result. This was the last call that shortened a value without notice. The range check runs on the rounded value.
  • isBigInteger() is replaced by fitsInt(), which answers the opposite question. The old name read as "is a large whole number" although it only checked the range, and callers negated it before toInt().
  • The value type is Stringable instead of object. Every class with __toString() is Stringable, so valid input is unchanged; any other object is now a TypeError at the call.
  • Decimal::create() returns a Decimal as is when no scale is passed. It returned a copy of an immutable object before.
  • truncate() goes through round() with ROUND_DOWN. Results are unchanged, including that it never adds zeros.

The upgrade guide covers the toInt() change with a 1.x / 2.0 table, the object type and the removed method. cakephp-decimal uses none of the changed calls.

toInt() dropped decimals without notice, the last call that did so. It now
refuses a value with decimals other than zero unless a rounding mode is
passed; ROUND_DOWN gives the old result. The range check runs on the
rounded value, so a value that rounds past the integer range overflows.

isBigInteger() is replaced by fitsInt(). The old name read as "is a large
whole number" while it only looked at the range, and callers always
negated it before toInt().

The value type is Stringable instead of object. Other objects were only
turned away after the call; every class with __toString() is Stringable.

create() returns a Decimal as is when no scale is passed. The object is
immutable, so the copy served no purpose.

truncate() goes through round() with ROUND_DOWN, with the same results as
before, including that it never adds zeros.
@dereuromark dereuromark added the enhancement New feature or request label Oct 11, 2026
@codecov

codecov Bot commented Oct 11, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.81%. Comparing base (d7e20c1) to head (1549b9a).

Additional details and impacted files
@@             Coverage Diff              @@
##               next      #30      +/-   ##
============================================
+ Coverage     95.59%   95.81%   +0.22%     
  Complexity      201      201              
============================================
  Files             1        1              
  Lines           454      454              
============================================
+ Hits            434      435       +1     
+ Misses           20       19       -1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@dereuromark
dereuromark merged commit e8e9c84 into next Oct 11, 2026
7 checks passed
@dereuromark
dereuromark deleted the feature/api-tidy branch October 11, 2026 17:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant