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
money
is a%Money{}
structopts
is a keyword list of options
Options
:rounding_mode
that defines how the number will be rounded. SeeDecimal.Context
. The default is:half_even
which is also known as "banker's rounding":currency_digits
which determines the rounding increment. The valid options are:cash
,:accounting
and:iso
or 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
:CHF
round to a minimum such as0.05
when its a cash amount. The rounding increment is applied when the option:currency_digits
is 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>