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

Question - Change decimal precision #189

Closed Macorreag closed 1 year ago

Macorreag commented 1 year ago

I have checked the configuration of the Module and I cannot find a parameter that allows me to set a precision in the Module

  %Money{amount: 999999, currency: :COP}
  |> Money.to_string()

This returns me : "$9.999,99"

It is possible to set it to take a precision of 3 decimal places and the result is something like.

"$9.99,999"

Nitrino commented 1 year ago

Hi @Macorreag Each currency has its own exponent, on the basis of which calculations and formatting are carried out. https://github.com/elixirmoney/money/blob/master/lib/money/currency.ex#L64

If you need a currency with a different exponent, then you can declare a custom currency https://github.com/elixirmoney/money#custom-currencies

Macorreag commented 1 year ago

Thanks @Nitrino for the quick response.