elixirmoney / money

Elixir library for working with Money safer, easier, and fun... Is an interpretation of the Fowler's Money pattern in fun.prog.
https://hex.pm/packages/money/
MIT License
826 stars 139 forks source link

`Money.to_string(Money.new(75000000, :UGX))` is converting to million instead of thousand #217

Closed flashup4all closed 5 months ago

flashup4all commented 5 months ago

In the following example, am expecting UGX to return something like a thousand Ush750,000.00 but am getting a million Ush75,000,000 instead.

Money.to_string(Money.new(75000000, :USD)) response = "$750,000.00"

Money.to_string(Money.new(75000000, :NGN)) response = "₦750,000.00"

Money.to_string(Money.new(75000000, :UGX)) response = "Ush75,000,000"

How do I ensure I get the appropriate output?

Nitrino commented 5 months ago

@flashup4all Each currency has an exponent that expresses the decimal relationship between the currency and its minor unit. For example, the U.S. dollar has 100 cents, which is 10 to the power of 2, so the exponent for the U.S. dollar is 2 and Money.new(100, :USD) is 1 U.S. dollar. According to ISO 4217, the currency UGX has an exponent equal to 0, which means that for a given currency, the minor unit is 1 UGX and Money.new(100, : UGX) is 100 UGX