Cldr.Unit.Format.to_iolist
to_iolist, go back to Cldr.Unit.Format module for more information.
Specs
to_iolist(list_or_number :: Cldr.Unit.value() | Cldr.Unit.t() | [Cldr.Unit.t()]) :: {:ok, String.t()} | {:error, {atom(), binary()}}
Formats a number into an iolist according to a unit definition for the current process's locale and backend.
The curent process's locale is set with
Cldr.put_locale/1.
See Cldr.Unit.Format.to_iolist/3 for full details.
Formats a number into an iolist according to a unit definition for a locale.
Arguments
list_or_numberis any number (integer, float or Decimal) or at:Cldr.Unitstruct or a list oft:Cldr.Unitstructsoptionsis 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: :long:grammatical_caseindicates that a localisation for the given locale and given grammatical case should be used. SeeCldr.Unit.known_grammatical_cases/0for the list of known grammatical cases. Note that not all locales define all cases. However all locales do define the:nominativecase, which is also the default.:genderindicates that a localisation for the given locale and given grammatical gender should be used. SeeCldr.Unit.known_grammatical_genders/0for the list of known grammatical genders. Note that not all locales define all genders.:list_optionsis 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/2which is used to format thenumber
Returns
{:ok, io_list}or{:error, {exception, message}}
Examples
iex> Cldr.Unit.Format.to_iolist Cldr.Unit.new!(:gallon, 123)
{:ok, ["123", " gallons"]}