Cldr v0.5.0 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, format: :short
{:ok, "123"}
iex> Cldr.Number.to_string 1234, format: :short
{:ok, "1K"}
iex> Cldr.Number.to_string 523456789, format: :short
{:ok, "523M"}
iex> Cldr.Number.to_string 7234567890, format: :short
{:ok, "7B"}
iex> Cldr.Number.to_string 7234567890, 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, format: :short, currency: "EUR"
{:ok, "€1K"}
iex> Cldr.Number.to_string 1234, format: :short, currency: "EUR", fractional_digits: 2
{:ok, "€1.23K"}
iex> Cldr.Number.to_string 1234, format: :short, currency: "JPY"
{:ok, "¥1K"}