Skip to content

Releases: elixir-cldr/cldr_numbers

Cldr Numbers version 2.11.0

18 Jan 23:27
Compare
Choose a tag to compare

Enhancements

  • Uses the number system defined by the locale if it is specified. The number system is defined as part of the U extension. The order of precedence is:

    • :default if no option is provided to MyApp.Cldr.Number.to_string/2 and no number system is defined in the locale

    • The option :number_system if it is provided to MyApp.Cldr.Number.to_string/2

    • The locale's number_system if it is defined and the option :number_system to MyApp.Cldr.Number.to_string/2 is not provided

Examples:

 # Locale defines a number system and no option :number_system is provided
 iex> TestBackend.Cldr.Number.to_string(1234, locale: "th-u-nu-thai")
 {:ok, "๑,๒๓๔"}

 # Locale defines a number system but an option :number_system is also provded which
 # take precedence
 iex> MyApp.Cldr.Number.to_string 1234, locale: "th-u-nu-latn", number_system: :thai
 {:ok, "๑,๒๓๔"}

 # A number system is defined in the locale but it is not supported by the
 # locale
 iex> MyApp.Cldr.Number.to_string 1234, locale: "en-AU-u-nu-thai"
 {:error,
  {Cldr.UnknownNumberSystemError,
   "The number system :thai is unknown for the locale named \"en\". Valid number systems are %{default: :latn, native: :latn}"}}
  • Uses the currency code defined by the locale if it is specified and the number format requested is :currency. The currency code is defined as part of the U extension. The order of precedence is:

    • The option :currency if it is provided to MyApp.Cldr.Number.to_string/2

    • The locale's currency code if it is defined and the option :currency to MyApp.Cldr.Number.to_string/2 is not provided

Examples:

 # Use the currency code :AUD specified in the locale
 iex> MyApp.Cldr.Number.to_string 1234, locale: "en-AU-u-cu-aud", format: :currency
 {:ok, "A$1,234.00"}

 # Use the current code :USD provided as an option in precedence over the currency code
 # defined by the locale
 iex> MyApp.Cldr.Number.to_string 1234, locale: "en-AU-u-cu-aud", format: :currency, currency: :USD
 {:ok, "$1,234.00"}
  • Uses the currency format defined by the locale if it is specified and the number format requested is :currency or :accounting. The currency format is defined as part of the U extension. The order of precedence is:

    • The locale's currency format if it is defined and the option :format to MyApp.Cldr.Number.to_string/2 is either :currency or :accounting. Therefore the locales currency format takes precendence over the :format argument but only if :format is a currency format.

    • The option :format in every other case

Examples:

 # Using in the locale currency format - just happens to be the same as the format option
 iex> MyApp.Cldr.Number.to_string -1234, locale: "en-AU-u-cu-aud-cf-standard", format: :currency
 {:ok, "A$-1,234.00"}

 # The locale format takes precedence over the format option
 iex> MyApp.Cldr.Number.to_string -1234, locale: "en-AU-u-cu-aud-cf-standard", format: :accounting
 {:ok, "A$-1,234.00"}

 iex> MyApp.Cldr.Number.to_string -1234, locale: "en-AU-u-cu-aud-cf-account", format: :accounting
 {:ok, "(A$1,234.00)"}

 iex> MyApp.Cldr.Number.to_string -1234, locale: "en-AU-u-cu-aud-cf-account", format: :currency
 {:ok, "(A$1,234.00)"}

Cldr Numbers version 2.10.0

14 Jan 23:40
Compare
Choose a tag to compare

Bug Fixes

  • Fixes formatting of negative percentages. Actually fixes an issue where the default negative format would be incorrect in many cases. Thanks to @maennchen. Closes #11.

Enhancements

  • Optionally logs a warning if compiling a number format at runtime. The warning is emitted only once for each format to reduce log clutter. The log warning is emitted if the backend configuration key :supress_warnings is set to false (this is the default value). The warn_once mechanism depends on the availability of the :persistent_term module which is only available from OTP 21.2 onwards. On earlier releases of OTP no warning will be emitted.

Cldr Numbers version 2.9.0

20 Oct 01:37
Compare
Choose a tag to compare

Enhancements

  • Adds option :currency_symbol to Cldr.Number.to_string/2. This option, when set to :iso changes a currency format to force using the ISO currency code instead of the native currency symbol.

Cldr Numbers version 2.8.0

09 Oct 22:42
Compare
Choose a tag to compare

Enhancements

  • Update ex_cldr to version 2.11.0 which encapsulates CLDR version 36.0.0 data.

Cldr Numbers version 2.7.2

06 Sep 21:44
Compare
Choose a tag to compare

Bug Fixes

  • Call Keyword.get_lazy/3 when accessing Cldr.default_locale/0 to avoid exceptions when no default backend is configured but an optional :backend has been passed.

Cldr Numbers version 2.7.1

23 Aug 01:21
Compare
Choose a tag to compare

Bug Fixes

  • Fix @spec for Cldr.Number.to_string/3 and Cldr.Number.to_string!/3

Cldr Numbers version 2.7.0

20 Aug 22:16
Compare
Choose a tag to compare

Enhancements

  • An option :backend can be passed to Cldr.Number.to_string/3 and it will be used if being called as Cldr.Number.to_string/2. This means that for a call like Cldr.Number.to_string(number, backend, options) which has an option :backend, the call can be replaced with Cldr.Number.to_string(number, options).

Cldr Numbers version 2.6.4

16 Jun 04:03
Compare
Choose a tag to compare

Bug Fixes

  • Fix the default value for the backend parameter for Cldr.Number.to_string/3

  • Allow Cldr.Number.to_string/3 to be called as Cldr.Number.to_string <number>, <options> as long as there is a default backend configured in config.exs.

Cldr Numbers version 2.6.3

14 Jun 23:34
Compare
Choose a tag to compare

Bug Fixes

  • Correctly interpret the special short format 0 to mean "format as a normal decimal or currency number". Thanks to @epilgrim. Closes #10

Cldr Numbers version 2.6.2

12 Jun 15:42
Compare
Choose a tag to compare

Bug Fixes

  • Don't transliterate in Cldr.Number.transliterate_digits/3 if from and to number systems are the same.