MyApp.Cldr.Unit.to_string-exclamation-mark
to_string-exclamation-mark
, go back to MyApp.Cldr.Unit module for more information.
Specs
to_string!( Cldr.Unit.value() | Cldr.Unit.t() | [Cldr.Unit.t(), ...], Keyword.t() ) :: String.t() | no_return()
Formats a list using to_string/3
but raises if there is
an error.
Arguments
list_or_number
is any number (integer, float or Decimal) or at:Cldr.Unit
struct or a list oft:Cldr.Unit
structsoptions
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
:grammatical_case
indicates that a localisation for the given locale and given grammatical case should be used. SeeCldr.Unit.known_grammatical_cases/0
for the list of known grammatical cases. Note that not all locales define all cases. However all locales do define the:nominative
case, which is also the default.:gender
indicates that a localisation for the given locale and given grammatical gender should be used. SeeCldr.Unit.known_gender/0
for the list of known grammatical genders. Note that not all locales define all genders. The default gender isCldr.Unit.default_gender/1
for the given locale.:list_options
is a keyword list of options for formatting a list which is passed through toCldr.List.to_string/3
. This is only applicable when formatting a list of units.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> MyApp.Cldr.Unit.to_string! 123, unit: :gallon
"123 gallons"
iex> MyApp.Cldr.Unit.to_string! 1, unit: :gallon
"1 gallon"
iex> MyApp.Cldr.Unit.to_string! 1, unit: :gallon, locale: "af"
"1 gelling"