Cldr.Unit.Format.to_string-exclamation-mark
to_string-exclamation-mark, go back to Cldr.Unit.Format module for more information.
Specs
to_string!( list_or_number :: Cldr.Unit.value() | Cldr.Unit.t() | [Cldr.Unit.t()] ) :: String.t() | no_return()
Formats a number into a string according to a unit definition for the current process's locale and backend or raises on error.
The curent process's locale is set with
Cldr.put_locale/1.
See Cldr.Unit.to_string!/3 for full details.
Specs
to_string!( Cldr.Unit.value() | Cldr.Unit.t() | [Cldr.Unit.t()], Cldr.backend() | Keyword.t(), Keyword.t() ) :: String.t() | no_return()
Formats a number into a string according to a unit definition for the current process's locale and backend or raises on error.
During processing any :format_options of a t:Cldr.Unit are merged with
options with options taking precedence.
Arguments
numberis any number (integer, float or Decimal) or at:Cldr.Unitstructbackendis any module that includesuse Cldrand therefore is aCldrbackend module. The default isCldr.default_backend!/0.optionsis a keyword list
Options
:unitis any unit returned byCldr.Unit.known_units/0. Ignored if the number to be formatted is at:Cldr.Unitstruct:localeis any valid locale name returned byCldr.known_locale_names/0or aCldr.LanguageTagstruct. The default isCldr.get_locale/0:styleis one of those returned byCldr.Unit.available_styles. The current styles are:long,:shortand:narrow. The default isstyle: :longAny other options are passed to
Cldr.Number.to_string/2which is used to format thenumber
Returns
formatted_stringorraises an exception
Examples
iex> Cldr.Unit.Format.to_string! Cldr.Unit.new!(:gallon, 123), MyApp.Cldr
"123 gallons"
iex> Cldr.Unit.Format.to_string! Cldr.Unit.new!(:gallon, 1), MyApp.Cldr
"1 gallon"
iex> Cldr.Unit.Format.to_string! Cldr.Unit.new!(:gallon, 1), MyApp.Cldr, locale: "af"
"1 gelling"