SoftBank.Cldr.Money.round

You're seeing just the function round, go back to SoftBank.Cldr.Money module for more information.
Link to this function

round(money, options \\ [])

View Source

Specs

round(Money.t(), Keyword.t()) :: Money.t()

Round a Money value into the acceptable range for the requested currency.

Arguments

  • money is a %:'Elixir.Money'{} struct

  • opts is a keyword list of options

Options

  • :rounding_mode that defines how the number will be rounded. See Decimal.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:

  1. Round to the appropriate number of fractional digits

  2. 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 as 0.05 when its a cash amount. The rounding increment is applied when the option :currency_digits is set to :cash

Examples

iex> SoftBank.Cldr.Money.round Money.new("123.73", :CHF), currency_digits: :cash
#Money<:CHF, 123.75>

iex> SoftBank.Cldr.Money.round Money.new("123.73", :CHF), currency_digits: 0
#Money<:CHF, 124>

iex> SoftBank.Cldr.Money.round Money.new("123.7456", :CHF)
#Money<:CHF, 123.75>

iex> SoftBank.Cldr.Money.round Money.new("123.7456", :JPY)
#Money<:JPY, 124>