View Source Cldr.Number.Formatter.Decimal (Cldr Numbers v2.33.3)

Formats a number according to a locale-specific predefined format or a user-defined format.

As a performance optimization, all decimal formats known at compile time are compiled into function that roughly halves the time to format a number compared to a non-precompiled format.

The available format styles for a locale can be returned by:

iex> {:ok, decimal_format_styles} = Cldr.Number.Format.decimal_format_styles_for("en", :latn, TestBackend.Cldr)
iex> Enum.sort(decimal_format_styles)
[
  :accounting,
  :accounting_alpha_next_to_number,
  :accounting_no_symbol,
  :currency,
  :currency_alpha_next_to_number,
  :currency_long,
  :currency_no_symbol,
  :percent,
  :scientific,
  :standard
]

This allows a number to be formatted in a locale-specific way but using a standard method of describing the purpose of the format.

Summary

Functions

Formats a number according to a decimal format string.

Functions

Link to this function

to_string(number, format, backend, options)

View Source
@spec to_string(
  Cldr.Math.number_or_decimal() | String.t(),
  String.t(),
  Cldr.backend(),
  Cldr.Number.Format.Options.t()
) :: {:ok, String.t()} | {:error, {atom(), String.t()}}

Formats a number according to a decimal format string.

This is a lower level formatting function. It is strongly advised to use Cldr.Number.to_string/2 or even better the MyApp.Cldr.Number.to_string/2 function where MyApp.Cldr is a Cldr backend module.

Arguments

  • number is an integer, float or Decimal or a string. A string is used only when composing formats.

  • format is a format string. See Cldr.Number for further information.

  • backend is any module that includes use Cldr and therefore is a Cldr backend module.

  • options is a Cldr.Number.Format.Options.t/0 of validated options. See Cldr.Number.to_string/2 for further information.