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
number
is any number (integer, float or Decimal) or at:Cldr.Unit
structbackend
is any module that includesuse Cldr
and therefore is aCldr
backend module. The default isCldr.default_backend!/0
.options
is a keyword list
Options
:unit
is any unit returned byCldr.Unit.known_units/0
. Ignored if the number to be formatted is at:Cldr.Unit
struct:locale
is any valid locale name returned byCldr.known_locale_names/0
or aCldr.LanguageTag
struct. The default isCldr.get_locale/0
:style
is one of those returned byCldr.Unit.available_styles
. The current styles are:long
,:short
and:narrow
. The default isstyle: :long
Any other options are passed to
Cldr.Number.to_string/2
which is used to format thenumber
Returns
formatted_string
orraises 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"