Releases: elixir-cldr/cldr_numbers
Cldr Numbers version 2.31.3
Bug Fixes
-
Support
format: :scientific
which is documented but was not implemented as a valid option. Thanks to @petrus-jvrensburg for the report. Closes #38. -
Don't override currency fractional digits when formatting a number. The format should always define the fractional digits unless overriden by the
:fractional_digits
option.
Cldr Numbers version 2.31.2
Bug Fixes
- Fixes formatting of numbers in locales where the locale has no RBNF. Thanks to @petrus-jvrensburg for the report. Closes #37.
Cldr Numbers version 2.31.1
Bug Fixes
- Ensure all RBNF rule names are valid function names. In at least one case ("2d_year") a rule name does not map to a valid Elixir function name. The rules are built with atom function names which is valid, but the string versions of that name do not parse.
MyApp.Cldr.Rbnf.Spellout.2d_year/2
does not parse, evening though the function exists. This can cause interoperabiity issues with other libraries the introspect code, likeinch_ex
. From this release, rule names are forced to be valid, parseable function names by prepending an "r" to the rule name if the rule name starts with a digit. Thanks to @ggarciajr for the report.
Cldr Numbers version 2.31.0
Enhancements
-
Updates to ex_cldr version 2.37.0 which includes data from CLDR release 43
-
Support a
:wrapper
function to returniodata
when used as an option toCldr.Number.to_string/2
.
Cldr Numbers version 2.30.1
Bug Fixes
- Fixes currency formats where the currency symbol is neither the first or last token. Thanks to @simoncocking for the issue. Closes #35.
Cldr Numbers version 2.30.0
Bug Fixes
-
Fix short formatting for decimal numbers. Thanks to @dbernheisel for the report. Closes #34.
-
Fix formatting negative numbers when the currency symbol results in an alphabetic character next to the number. In these cases a special format
:currency_alpha_next_to_number
(or:accounting_alpha_next_to_number
) is used. These formats are only available in CLDR42 or later and thereforeex_cldr
version 2.35.0 or later is required.
Enhancements
-
Supports the
:default_currency_format
backend configuration option introduced inex_cldr
version 2.35.0. -
Adds
:from_locale
as a valid value to the:currency
option toCldr.Number.to_string/3
. If set, the currency is derived from the locale.
Cldr Numbers version 2.29.0
Behavior change
-
In prior releases formatting a number as
format: :currency
would derive the currency code from the locale if no:currency_code
was provided. This is no longer the case. As of CLDR42 a format:currency_no_symbol
is defined to allow formatting of the number without an associated symbol. Now whenformat: :currency
is passed without a:currency_code
option, the format is changed toformat: :currency_no_symbol
. To retain the existing behaviour, passcurrency_code: Cldr.Currency.currency_from_locale(locale)
as an option. -
In prior releases the currency format (:currency or :accounting) would be overriden by any choice expressed in the locale. That is no longer the case from this release. To retain the existing behaviour, pass
format: Cldr.Currency.currency_format_from_locale(locale)
as an option.
Enhancements
- Adds an option
:wrapper
toCldr.Number.to_string/2
. The argument is a 2-arity function that receives the parametersstring
andtag
wheretag
is one of:number
,:currency_symbol
,:currency_space
,:literal
,:quote
,:percent
,:permille
,:minus
or:plus
. The function must return a string or a "safe string" such as that returned byPhoenix.HTML.Tag.content_tag/3
. The function can be used to wrap format elements in HTML or other tags. Thanks to @rubas for the motivation and review. Example:
iex> Cldr.Number.to_string(100, format: :currency, currency: :USD, wrapper: fn
...> string, :currency_symbol -> "<span class=\"symbol\">" <> string <> "</span>"
...> string, :number -> "<span class=\"number\">" <> string <> "</span>"
...> string, :currency_space -> "<span>" <> string <> "</span>"
...> string, _other -> string
...> end)
{:ok, "<span class=\"symbol\">$</span><span class=\"number\">100.00</span>"}
# It is also possible and recommended to use the `Phoenix.HTML.Tag.content_tag/3`
# function if wrapping HTML tags since these will ensure HTML entities are
# correctly encoded. For example:
iex> Cldr.Number.to_string(100, format: :currency, currency: :USD, wrapper: fn
...> string, :currency_symbol -> Phoenix.HTML.Tag.content_tag(:span, string, class: "symbol")
...> string, :number -> Phoenix.HTML.Tag.content_tag(:span, string, class: "number")
...> string, :currency_space -> Phoenix.HTML.Tag.content_tag(:span, string)
...> string, _other -> string
...> end)
{:ok, "<span class=\"symbol\">$</span><span class=\"number\">100.00</span>"}
-
Adds the number formats
:currency_no_symbol
and:accounting_no_symbol
that can be used to format currency amounts without an associated currency symbol. -
Removes the
Cldr.Number.to_string/3
requirement for a currency to be provided (or derived) when the format is:currency
. If a currency is provided, the format:currency
is used. If a currency is not provided, the format:currency_no_symbol
is used.
Cldr Numbers version 2.28.0
Enhancements
- Encapsulates CLDR 42 data. Unless otherwise noted, all the changes are reflected in
ex_cldr
libraries and functions.
Updated data from CLDR
- Two new values for pattern elements used for currency format elements:
alpha_next_to_number
: A pattern to use when the currency symbol would result in letter characters being adjacent to the numeric value; typically this adds a no-break space between the currency symbol and numeric value, if the standard currency format pattern does not already have a space. This provides an improved alternative to the currency spacing patterns.no_currency
: A pattern to use when currency-style formats are desired but without the actual symbol (as in a table of currency values all fo the same currency).
- For the currency formats element, a new element
currency_pattern_append_ISO
containing a pattern that shows how to append an ISO currency symbol (¤¤) to a currency pattern using a standard currency symbol (¤); this is needed for certain types of currency display. - Although these data changes are incorporated, the formatting functions do not expose them. They will be added in an update to
ex_cldr_numbers
by year end 2022.
Cldr Numbers version 2.27.3
Bug Fixes
-
Cldr.Number.to_string/3
withformat: :narrow
and:currency
set will use the currency's narrow symbol. -
Apply currency spacing for short formats (previously not being applied)