Cldr.Number.Formatter.Decimal (Cldr Numbers v2.35.2)
View SourceFormats 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
@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
- numberis an integer, float or Decimal or a string. A string is used only when composing formats.
- formatis a format string. See- Cldr.Numberfor further information.
- backendis any module that includes- use Cldrand therefore is a- Cldrbackend module.
- optionsis a- Cldr.Number.Format.Options.t/0of validated options. See- Cldr.Number.to_string/2for further information.