Money.put_fraction

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

put_fraction(money, fraction \\ 0)

View Source

Set the fractional part of a Money.

Arguments

  • money is a %Money{} struct

  • fraction is an integer amount that will be set as the fraction of the money

Notes

The fraction can only be set if it matches the number of decimal digits for the currency associated with the money. Therefore, for a currency with 2 decimal digits, the maximum for fraction is 99.

Examples

iex> Money.put_fraction Money.new(:USD, "2.49"), 99
#Money<:USD, 2.99>

iex> Money.put_fraction Money.new(:USD, "2.49"), 0
#Money<:USD, 2.0>

iex> Money.put_fraction Money.new(:USD, "2.49"), 999
{:error,
 {Money.InvalidAmountError, "Rounding up to 999 is invalid for currency :USD"}}