Money.round
round, go back to Money module for more information.
Specs
Round a Money value into the acceptable range for the requested currency.
Arguments
moneyis a%Money{}structoptsis a keyword list of options
Options
:rounding_modethat defines how the number will be rounded. SeeDecimal.Context. The default is:half_evenwhich is also known as "banker's rounding":currency_digitswhich determines the rounding increment. The valid options are:cash,:accountingand:isoor an integer value representing the rounding factor. The default is:iso.
Notes
There are two kinds of rounding applied:
Round to the appropriate number of fractional digits
Apply an appropriate rounding increment. Most currencies round to the same precision as the number of decimal digits, but some such as
:CHFround to a minimum such as0.05when its a cash amount. The rounding increment is applied when the option:currency_digitsis set to:cash
Examples
iex> Money.round Money.new("123.73", :CHF), currency_digits: :cash
#Money<:CHF, 123.75>
iex> Money.round Money.new("123.73", :CHF), currency_digits: 0
#Money<:CHF, 124>
iex> Money.round Money.new("123.7456", :CHF)
#Money<:CHF, 123.75>
iex> Money.round Money.new("123.7456", :JPY)
#Money<:JPY, 124>