Skip to content
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

Money.split/2 cash option behaving wrong #56

Closed
maennchen opened this issue Feb 21, 2018 · 2 comments
Closed

Money.split/2 cash option behaving wrong #56

maennchen opened this issue Feb 21, 2018 · 2 comments

Comments

@maennchen
Copy link

The documentation mentions this example:

iex> Money.round Money.new("123.7456", :CHF), cash: true
#Money<:CHF, 125>

The correct result should be #Money<:CHF, 125.75> though, since the smallest coin in CHF is 0.05 (5 centimes called "Rappen"). See in the table here: https://en.wikipedia.org/wiki/Swiss_franc#Coins

In accounting the smallest precision is 0.01 (1 centime).

@kipcole9
Copy link
Owner

kipcole9 commented Feb 21, 2018

Apologies, definitely a bug. The formatting output is rounding correctly:

iex> Money.to_string Money.new("123.7456", :CHF), cash: true
{:ok, "CHF123.75"}

But Money.round/2 is not. I will fix ASAP.

@kipcole9
Copy link
Owner

As of this commit the rounding is now correctly made. Note too that the option to specify cash digits rounding is currency_digits: :cash, not cash: true. The updated release will be in hex in a few minutes.

Changelog for Money v2.2.1

This is the changelog for Money v2.2.1 released on February 22, 2018. For older changelogs please consult the release tag on GitHub

Bug Fixes

  • Correctly round to cash increment Money.round/2 now correctly uses the rounding increment for a currency. This is relevant for currencies like :AUD and :CHF which have minimum cash rounding of 0.05 even though the accounting increment is 0.01. Thanks to @maennchen. Closes Money.split/2 cash option behaving wrong #56.

  • Update documentation for Money.round/2 to correctly refer to the option :currency_digits with the valid options of :cash, :accounting and :iso. The default is :iso. The option cash: true is invalid.

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

No branches or pull requests

2 participants