Skip to content

Add Money#to_nearest_cash_value to return a rounded Money instance to the smallest denomination #1146

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

Merged
merged 5 commits into from
Jul 24, 2025

Conversation

sunny
Copy link
Contributor

@sunny sunny commented Jul 16, 2025

This new method allows you to get a new Money instance rounded to the smallest denomination.

Closes #1130

Allows us to simplify:

Money.new(Money.new(1_11, "CHF").round_to_nearest_cash_value, "CHF")

to:

Money.new(1_11, "CHF").to_nearest_cash_value

Ideally the #round_to_nearest_cash_value should have always returned an instance to act like the #round method. Introducing a new method avoids breaking previous code.

…to the smallest denomination

This new method allows you to get a new Money instance rounded to the smallest denomination.

Closes RubyMoney#1131
@sunny sunny force-pushed the add-to_nearest_cash_value branch from b97ff87 to 52b15e9 Compare July 16, 2025 11:54
yukideluxe
yukideluxe previously approved these changes Jul 23, 2025
Copy link
Member

@yukideluxe yukideluxe left a comment

Choose a reason for hiding this comment

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

I really like this! Just a note about the link to BigDecimal ROUND_MODE that I updated in one of my PRs, it seems that git did not detect a conflict there 😳

Copy link
Member

@yukideluxe yukideluxe left a comment

Choose a reason for hiding this comment

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

thanks!

@yukideluxe yukideluxe merged commit 4766542 into RubyMoney:main Jul 24, 2025
6 checks passed
@sunny
Copy link
Contributor Author

sunny commented Jul 24, 2025

it seems that git did not detect a conflict there 😳

It did, I just add the wrong one in my conflicts 😅

Thank you for the swift merge :)

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.

Thousands separator and smallest_denomination not working for CHF
2 participants