Cldr.Number.System.to_system
to_system
, go back to Cldr.Number.System module for more information.
Specs
to_system(Cldr.Math.number_or_decimal(), atom(), Cldr.backend()) :: {:ok, binary()} | {:error, {module(), String.t()}}
Converts a number into the representation of a non-latin number system.
This function converts numbers to a known number system only, it does not provide number formatting.
Arguments
number
is afloat
,integer
orDecimal
system_name
is any number system name returned byCldr.known_number_systems/0
or a number system type returned byCldr.known_number_system_types/0
backend
is anyCldr
backend. That is, any module that containsuse Cldr
Returns
{:ok, string_of_digits}
or{:error, {exception, reason}}
Notes
There are two types of number systems in CLDR:
:numeric
in which the number system defines a direct mapping between the latin digits0..9
into a the number system equivalent. In this case,to_system/3
invokesCldr.Number.Transliterate.transliterate_digits/3
for the given number.:algorithmic
in which the number system does not have the same structure as the:latn
number system and therefore the conversion is done algorithmically. For CLDR the algorithm is implemented throughCldr.Rbnf
rulesets. These rulesets are considered by CLDR to be less rigorous than the:numeric
number systems and caution and testing for a specific use case is recommended.
Examples
iex> Cldr.Number.System.to_system 123456, :hebr, TestBackend.Cldr
{:ok, "קכ״ג׳תנ״ו"}
iex> Cldr.Number.System.to_system 123, :hans, TestBackend.Cldr
{:ok, "一百二十三"}
iex> Cldr.Number.System.to_system 123, :hant, TestBackend.Cldr
{:ok, "一百二十三"}
iex> Cldr.Number.System.to_system 123, :hansfin, TestBackend.Cldr
{:ok, "壹佰贰拾叁"}