Cldr Numbers v2.7.2 Cldr.Number.Formatter.Short View Source
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 readibility.
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.
Link to this section Summary
Link to this section Functions
Link to this function
to_string(number, style, backend, options)
View Sourceto_string( Cldr.Math.number_or_decimal(), atom(), Cldr.backend(), Cldr.Number.Format.Options.t() ) :: {:ok, String.t()} | {:error, {module(), String.t()}}