Skip to content

Releases: kipcole9/money

Money version 3.4.4

03 Jun 03:43
Compare
Choose a tag to compare

Enhancements

  • Supports passing an Cldr.Number.Formation.Options.t as alternative to a Keyword.t for options to Money.to_string/2. Performance is doubled when using pre-validated options which is useful if formatting is being executed in a tight loop.

An example of this usage is:

  iex> money = Money.new(:USD, 100)

  # Apply any options required as a keyword list
  # Money will take care of managing the `:currency` option
  iex> options = []

  iex> {:ok, options} = Cldr.Number.Format.Options.validate_options(0, backend, options)
  iex> Money.to_string(money, options)

The 0 in validate_options is used to determine the sign of the amount because that can influence formatting - for example the accounting format often uses (1234) as its format. If you know your amounts are always positive, just use 0.

If the use case may have both positive and negative amounts, generate two option sets (one with the positive number and one with the negative). Then use the appropriate option set. For example:

  iex> money = Money.new(:USD, 1234)

  # Add options as required
  # Money will take care of managing the `:currency` option
  iex> options = []

  iex> {:ok, positive_options} = Cldr.Number.Format.Options.validate_options(0, backend, options)
  iex> {:ok, negative_options} = Cldr.Number.Format.Options.validate_options(-1, backend, options)

  iex> if Money.cmp(money, Money.zero(:USD)) == :gt do
  ...>   Money.to_string(money, positive_options)
  ...> else
  ...>   Money.to_string(money, negative_options)
  ...> end

Money version 3.4.3

02 Jun 15:35
Compare
Choose a tag to compare

Bug Fixes

  • Ensure Money.to_string!/2 properly raises

  • Add specs for Money.to_string/2 and Money.to_string!/2

Thanks to @rodrigues for the report, tests and PR.

Money version 3.4.2

16 Apr 03:31
Compare
Choose a tag to compare

Bug Fixes

  • Money.put_fraction/2 now correctly allows setting the fraction to 0.

Enhancements

  • Money.round/2 allows setting :currency_digits to an integer number of digits in addition to the options :iso, :cash and :accounting. The default remains :iso.

  • Improves the documentation for Money.to_string/2.

Money version 3.4.1

05 Apr 16:26
Compare
Choose a tag to compare

Bug Fixes

Money version 3.4.0

28 Mar 12:46
Compare
Choose a tag to compare

Enhancements

Money version 3.3.1

08 Mar 09:45
Compare
Choose a tag to compare

Bug Fixes

  • Fix or silence dialyzer warnings

Money version 3.3.0

24 Feb 16:03
Compare
Choose a tag to compare

Enhancements

  • Adds Money.put_fraction/2. This will set the fractional part of a money to the specified integer amount. Examples:
  iex> Money.put_fraction Money.new(:USD, "2.49"), 99
  #Money<:USD, 2.99>

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

Bug Fixes

  • Parsing money strings now uses a more complete set of character definitions for decimal and grouping separators based upon the characters.json file of the "en" locale.

Money version 3.2.4

13 Feb 11:25
Compare
Choose a tag to compare

Bug Fixes

Enhancements

  • Adds a :fuzzy option to Money.parse/2 that uses String.jaro_distance/2 to help determine if the provided currency text can be resolved as a currency code. For example:
  iex> Money.parse("100 eurosports", fuzzy: 0.8)
  #Money<:EUR, 100>

  iex> Money.parse("100 eurosports", fuzzy: 0.9)
  {:error,
   {Money.Invalid, "Unable to create money from \"eurosports\" and \"100\""}}

Money version 3.2.3

12 Feb 11:42
Compare
Choose a tag to compare

Bug Fixes

  • Correctly parse money strings with unicode currency symbols like "€". Closes #95. Thanks to @crbelaus.

Money version 3.2.2

10 Feb 01:16
Compare
Choose a tag to compare

Enhancements

  • Improves parsing of money strings. Parsing now uses various strings that CLDR knows about. Some examples:
  iex> Money.parse "$au 12 346", locale: "fr"
  #Money<:AUD, 12346>
  iex> Money.parse "12 346 dollar australien", locale: "fr"
  #Money<:AUD, 12346>
  iex> Money.parse "A$ 12346", locale: "en"
  #Money<:AUD, 12346>
  iex> Money.parse "australian dollar 12346.45", locale: "en"
  #Money<:AUD, 12346.45>
  iex> Money.parse "AU$ 12346,45", locale: "de"
  #Money<:AUD, 12346.45>

  # Can also return the strings available for a given currency
  # and locale
  iex> Cldr.Currency.strings_for_currency :AUD, "de"
  ["aud", "au$", "australischer dollar", "australische dollar"]

  # Round trip formatting also seems to be ok
  iex> {:ok, string} = Cldr.Number.to_string 1234, Money.Cldr, currency: :AUD
  {:ok, "A$1,234.00"}
  iex> Money.parse string
  #Money<:AUD, 1234.00>