Skip to content

remove deprecations related with rounding mode#1144

Merged
yukideluxe merged 4 commits intomainfrom
jl-remove-rounding-mode
Jul 23, 2025
Merged

remove deprecations related with rounding mode#1144
yukideluxe merged 4 commits intomainfrom
jl-remove-rounding-mode

Conversation

@yukideluxe
Copy link
Member

Hello @RubyMoney/core and contributors!

Another deprecation out of the way before releasing a new major version! 🎉 This one was originally introduced in this PR.

As explained in this comment, the rationale for changing the default rounding mode is:

the default rounding mode is ROUND_HALF_EVEN and they way it works might not be expected by people using this gem. It works best when aggregating with bigger amount of data and has an effect of minimizing rounding error, however when dealing with one off cases (for example rounding the result of a currency exchange) it's probably not as useful.

Out of curiosity – and to make sure we’re making the right call! – I asked ChatGPT for a summary of the different rounding modes. Besides summarizing them, it also brought up two interesting points:

  • As of Ruby 3.2, the default rounding mode is now BigDecimal::ROUND_HALF_UP. I am always down on using the defaults. I double-checked it in the official docs:
    CleanShot 2025-07-14 at 19 55 48@2x

  • It also noted: "Use ROUND_HALF_EVEN when doing financial calculations to reduce cumulative rounding error". This had me thinking because, after all, this gem is called money. But as @antstorm pointed out, many users might not be doing large-scale aggregations and could get unexpected results with ROUND_HALF_EVEN because of the way it behaves (more about that at the bottom).

I’m inclined to go ahead and change the default to ROUND_HALF_UP, especially since it's easy to override if someone needs the previous behavior. Plus, this comment mentions that Stripe uses ROUND_HALF_UP so I am convinced 💪🏻

PS: Quick ChatGPT summary of the difference between the two modes and a table with examples:

  • With ROUND_HALF_UP, every .5 always rounds up. This can introduce a small upward bias over time.
  • With ROUND_HALF_EVEN, .5 values sometimes round up, sometimes down — helping cancel out rounding bias in large datasets. This is ideal for financial, banking, and accounting software.
CleanShot 2025-07-14 at 20 11 56@2x

@@ -487,7 +487,7 @@ You can set the default rounding mode by passing one of the `BigDecimal` mode en
```ruby
Copy link

Choose a reason for hiding this comment

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

Do we want to update something more in the README? In the example code, for example, it passes BigDecimal::ROUND_HALF_UP to the round method, even though it's the new default.

Copy link
Member Author

Choose a reason for hiding this comment

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

good catch! done! dc3f52b

Copy link
Member

@sunny sunny left a comment

Choose a reason for hiding this comment

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

🙌🏻

@yukideluxe yukideluxe force-pushed the jl-stop-setting-default-currency branch from 34771d0 to 12c79f4 Compare July 22, 2025 17:27
@yukideluxe yukideluxe force-pushed the jl-remove-rounding-mode branch from 45a8b06 to 106785c Compare July 22, 2025 17:55
@yukideluxe yukideluxe force-pushed the jl-stop-setting-default-currency branch from 2f0f4bd to 61c1c5f Compare July 22, 2025 17:56
@yukideluxe yukideluxe force-pushed the jl-remove-rounding-mode branch from 106785c to db6571f Compare July 22, 2025 17:56
@yukideluxe yukideluxe force-pushed the jl-remove-rounding-mode branch from 8910096 to b6ffadd Compare July 23, 2025 12:45
@yukideluxe yukideluxe force-pushed the jl-stop-setting-default-currency branch 2 times, most recently from aeb1f19 to 6c1d7c7 Compare July 23, 2025 12:48
@yukideluxe yukideluxe force-pushed the jl-remove-rounding-mode branch from b6ffadd to dde6e90 Compare July 23, 2025 12:50
Base automatically changed from jl-stop-setting-default-currency to main July 23, 2025 12:52
yukideluxe and others added 3 commits July 23, 2025 14:52
@yukideluxe yukideluxe force-pushed the jl-remove-rounding-mode branch from dde6e90 to 4d2ca1b Compare July 23, 2025 12:52
@yukideluxe yukideluxe force-pushed the jl-remove-rounding-mode branch from 095860b to dc3f52b Compare July 23, 2025 12:58
@yukideluxe yukideluxe merged commit 377b0e8 into main Jul 23, 2025
6 checks passed
@yukideluxe yukideluxe deleted the jl-remove-rounding-mode branch July 23, 2025 13:01
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.

3 participants