Cldr Units v2.1.0 TestBackend.Cldr.Number.System View Source
Link to this section Summary
Functions
Returns the actual number system from a number system type
Returns the number systems available for a locale
or {:error, message}
if the locale is not known
Returns the number systems available for a locale
or {:error, message}
if the locale is not known
Returns a number system name for a given locale and number system reference
Converts a number into the representation of a non-latin number system. Returns a converted string or raises on error
Converts a number into the representation of a non-latin number system
Link to this section Functions
number_system_for( TestBackend.Cldr.Locale.name() | Cldr.LanguageTag.t(), System.name() ) :: {:ok, [atom(), ...]} | {:error, {Exception.t(), String.t()}}
Returns the actual number system from a number system type.
locale
is any valid locale name returned byCldr.known_locale_names/0
or aCldr.LanguageTag
struct returned byCldr.Locale.new!/1
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
This function will decode a number system type into the actual number system. If the number system provided can’t be decoded it is returned as is.
Examples
iex> Cldr.Number.System.number_system_for "th", :latn, TestBackend.Cldr
{:ok, %{digits: "0123456789", type: :numeric}}
iex> Cldr.Number.System.number_system_for "en", :default, TestBackend.Cldr
{:ok, %{digits: "0123456789", type: :numeric}}
iex> Cldr.Number.System.number_system_for "he", :traditional, TestBackend.Cldr
{:ok, %{rules: "hebrew", type: :algorithmic}}
iex> Cldr.Number.System.number_system_for "en", :finance, TestBackend.Cldr
{
:error,
{Cldr.UnknownNumberSystemError,
"The number system :finance is unknown for the locale named \"en\". Valid number systems are %{default: :latn, native: :latn}"}
}
iex> Cldr.Number.System.number_system_for "en", :native, TestBackend.Cldr
{:ok, %{digits: "0123456789", type: :numeric}}
number_system_names_for(TestBackend.Cldr.Locale.name() | Cldr.LanguageTag.t()) :: [atom()]
Returns the number systems available for a locale
or {:error, message}
if the locale is not known.
locale
is any valid locale name returned byTestBackend.Cldr.known_locale_names/0
or aCldr.LanguageTag
struct returned byTestBackend.Cldr.Locale.new!/1
Examples
iex> TestBackend.Cldr.Number.System.number_system_names_for "en"
{:ok, [:latn]}
iex> TestBackend.Cldr.Number.System.number_system_names_for "zz"
{:error, {Cldr.UnknownLocaleError, "The locale \"zz\" is not known."}}
number_systems_for(TestBackend.Cldr.Locale.name() | Cldr.LanguageTag.t()) :: Map.t()
Returns the number systems available for a locale
or {:error, message}
if the locale is not known.
locale
is any valid locale name returned byTestBackend.Cldr.known_locale_names/0
or aCldr.LanguageTag
struct returned byTestBackend.Cldr.Locale.new!/1
Examples
iex> TestBackend.Cldr.Number.System.number_systems_for "en"
{:ok, %{default: :latn, native: :latn}}
iex> TestBackend.Cldr.Number.System.number_systems_for "th"
{:ok, %{default: :latn, native: :thai}}
iex> TestBackend.Cldr.Number.System.number_systems_for "zz"
{:error, {Cldr.UnknownLocaleError, "The locale \"zz\" is not known."}}
number_systems_like( Cldr.LanguageTag.t() | TestBackend.Cldr.Locale.locale_name(), Cldr.Number.System.system_name() ) :: {:ok, List.t()} | {:error, tuple()}
system_name_from( Cldr.Number.System.system_name(), TestBackend.Cldr.Locale.locale_name() | Cldr.LanguageTag.t() ) :: {:ok, atom()} | {:error, {Exception.t(), String.t()}}
Returns a number system name for a given locale and number system reference.
system_name
is any number system name returned byTestBackend.Cldr.known_number_systems/0
or a number system type returned byTestBackend.Cldr.known_number_system_types/0
locale
is any valid locale name returned byTestBackend.Cldr.known_locale_names/0
or aCldr.LanguageTag
struct returned byTestBackend.Cldr.Locale.new!/1
Number systems can be references in one of two ways:
As a number system type such as :default, :native, :traditional and :finance. This allows references to a number system for a locale in a consistent fashion for a given use
WIth the number system name directly, such as :latn, :arab or any of the other 70 or so
This function dereferences the supplied system_name
and returns the
actual system name.
Examples
ex> TestBackend.Cldr.Number.System.system_name_from(:default, "en")
{:ok, :latn}
iex> TestBackend.Cldr.Number.System.system_name_from("latn", "en")
{:ok, :latn}
iex> TestBackend.Cldr.Number.System.system_name_from(:native, "en")
{:ok, :latn}
iex> TestBackend.Cldr.Number.System.system_name_from(:nope, "en")
{
:error,
{Cldr.UnknownNumberSystemError, "The number system :nope is unknown"}
}
Note that return value is not guaranteed to be a valid number system for the given locale as demonstrated in the third example.
Converts a number into the representation of a non-latin number system. Returns a converted string or raises on error.
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
See Cldr.Number.System.to_string/2
for further
information.
Examples
iex> TestBackend.Cldr.Number.System.to_system! 123, :hans
"一百二十三"
iex> TestBackend.Cldr.Number.System.to_system! 123, :hant
"一百二十三"
iex> TestBackend.Cldr.Number.System.to_system! 123, :hansfin
"壹佰贰拾叁"
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.
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
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/2
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> TestBackend.Cldr.Number.System.to_system 123456, :hebr
{:ok, "ק׳׳ת׳"}
iex> TestBackend.Cldr.Number.System.to_system 123, :hans
{:ok, "一百二十三"}
iex> TestBackend.Cldr.Number.System.to_system 123, :hant
{:ok, "一百二十三"}
iex> TestBackend.Cldr.Number.System.to_system 123, :hansfin
{:ok, "壹佰贰拾叁"}