View Source Cldr.Number.Formatter.Short (Cldr Numbers v2.31.3)
Formats a number according to the locale-specific :short
formats
This is best explained by some examples:
iex> Cldr.Number.to_string 123, TestBackend.Cldr, format: :short
{:ok, "123"}
iex> Cldr.Number.to_string 1234, TestBackend.Cldr, format: :short
{:ok, "1K"}
iex> Cldr.Number.to_string 523456789, TestBackend.Cldr, format: :short
{:ok, "523M"}
iex> Cldr.Number.to_string 7234567890, TestBackend.Cldr, format: :short
{:ok, "7B"}
iex> Cldr.Number.to_string 7234567890, TestBackend.Cldr, format: :long
{:ok, "7 billion"}
These formats are compact representations however they do lose precision in the presentation in favour of human readability.
Note that for a :currency
short format the number of decimal places
is retrieved from the currency definition itself. You can see the difference
in the following examples:
iex> Cldr.Number.to_string 1234, TestBackend.Cldr, format: :short, currency: "EUR"
{:ok, "€1K"}
iex> Cldr.Number.to_string 1234, TestBackend.Cldr, format: :short, currency: "EUR", fractional_digits: 2
{:ok, "€1.23K"}
iex> Cldr.Number.to_string 1234, TestBackend.Cldr, format: :short, currency: "JPY"
{:ok, "¥1K"}
This module is not part of the public API and is subject to change at any time.
Summary
Functions
Returns the exponent that will be applied when formatting the given number as a short format.
Functions
Returns the exponent that will be applied when formatting the given number as a short format.
This function is primarily intended to support
pluralization for compact numbers (numbers
formatted with the format: :short
option) since
some languages pluralize compact numbers differently
to a fully expressed number.
Such rules are defined for the locale "fr" from CLDR version 38 with the intention that additional rules will be added in later versions.
Examples
iex> Cldr.Number.Formatter.Short.short_format_exponent 1234
{1000, 1}
iex> Cldr.Number.Formatter.Short.short_format_exponent 12345
{10000, 2}
iex> Cldr.Number.Formatter.Short.short_format_exponent 123456789
{100000000, 3}
iex> Cldr.Number.Formatter.Short.short_format_exponent 123456789, locale: "th"
{100000000, 3}
@spec to_string( Cldr.Math.number_or_decimal(), atom(), Cldr.backend(), Cldr.Number.Format.Options.t() ) :: {:ok, String.t()} | {:error, {module(), String.t()}}