# `Cldr.Number.System`
[🔗](https://github.com/elixir-cldr/cldr_numbers/blob/v2.38.2/lib/cldr/number/system.ex#L1)

Number systems information is used to define different representations
for numeric values to an end user. Numbering systems are defined in CLDR
as one of two different types: algorithmic and numeric.

Numeric systems are simply a decimal based system that uses a
predefined set of digits to represent numbers. Examples are
Western digits (ASCII digits), Thai digits, Devanagari digits.

Algorithmic systems are more complex in nature, since the proper
formatting and presentation of a numeric quantity is based on some
algorithm or set of rules. Examples are Chinese numerals, Hebrew numerals,
or Roman numerals.

In CLDR, the rules for presentation of numbers in an algorithmic system
are defined using the rules based number formats (RBNF) which are
implemented in `Cldr.Number.Rbnf`.

### Number system attributes

Attributes for a number system map are as follows:

* `:id` specifies the name of the number system that can be used to designate
  its use in formatting.
* `:type` specifies whether the number system is algorithmic or numeric.
* `:digits`For numeric systems, specifies the digits used to represent numbers,
  in order, starting from zero.
* `:rules` specifies the RBNF ruleset to be used for formatting numbers from this
  number system. The rules specifier can contain simply a ruleset name, in
  which case the ruleset is assumed to be found in the rule set grouping
  "NumberingSystemRules". Alternatively, the specifier can denote a specific
  locale, ruleset grouping, and ruleset name, separated by slashes.

An example of a number system map is:

    iex> Cldr.Number.System.number_systems()[:latn]
    %{type: :numeric, digits: "0123456789"}

    iex> Cldr.Number.System.number_systems()[:taml]
    %{type: :algorithmic, rules: "tamil"}

### Number system types

Each number system also categories number systems into various types:

* `:native` defines the number system used for the native digits,
   usually defined as a part of the script used to write the language.
  `:native` number system can only be a numeric positional decimal-digit
   number system, using digits with General_Category=Decimal_Number. Note
   that In locales where the native number system is the default, it is
   assumed that the number system "latn" (Western digits 0-9) is always
   acceptable, and can be selected using the `-nu` keyword as part of a Unicode
   locale name.

* `:traditional` defines the traditional numerals for a locale. This numbering
  system may be numeric or algorithmic. If the traditional number system is
  not defined, the native number system is used as a fallback.

* `:finance` defines the number system used for financial quantities. This
  number system may be numeric or algorithmic. This is often used for
  ideographic languages such as Chinese, where it would be easy to alter an amount
  represented in the default number system simply by adding additional strokes.
  If the financial number system is not specified, the
  default number system is used as a fallback.

An example of a number system map for the `:zh` locale is:

    iex> Cldr.Number.System.number_systems_for(:zh, MyApp.Cldr)
    {:ok,
     %{default: :latn, native: :hanidec, traditional: :hans, finance: :hansfin}}

This indicates that for the locale `:zh`, the number systems `:latn`, `:hanidec`,
`:hans` and `:hansfin` are supported. These number systems are a mix of
nuemeric systems and algorithmic systems.

### Specifying the number system in a locale name

The types defined for other number systems can be used in a Unicode locale
identifier to select the proper number system without having to know the
specific number system by name. For example:

* To select the Hindi language using the native digits for numeric formatting, use
  locale ID: "hi-IN-u-nu-native".

* To select the Chinese language using the appropriate financial numerals, use
  locale ID: "zh-u-nu-finance".

* To select the Tamil language using the traditional Tamil numerals, use
  locale ID: "ta-u-nu-traditio".

* To select the Arabic language using western digits 0-9, use locale ID:
  "ar-u-nu-latn".

# `system_name`

```elixir
@type system_name() :: atom()
```

# `types`

```elixir
@type types() :: :default | :native | :traditional | :finance
```

# `algorithmic_systems`
*since 2.32.0* 

Returns a map of the number systems that are
algorithmic.

Algorithmic number systems don't have decimal
digits. Numbers are formed by algorithm using
rules based number formats.

The `:rules` field contains the name of the
RBNF rule that will be used with formatting
a number with `format: :standard` (which is
also the default when no `:format` is specified).

See also `Cldr.Number.System.numeric_systems/0`.

### Example

    ==> Cldr.Number.System.algorithmic_systems()
    %{
      roman: %{type: :algorithmic, rules: "roman-upper"},
      armn: %{type: :algorithmic, rules: "armenian-upper"},
      armnlow: %{type: :algorithmic, rules: "armenian-lower"},
      cyrl: %{type: :algorithmic, rules: "cyrillic-lower"},
      ethi: %{type: :algorithmic, rules: "ethiopic"},
      geor: %{type: :algorithmic, rules: "georgian"},
      grek: %{type: :algorithmic, rules: "greek-upper"},
      greklow: %{type: :algorithmic, rules: "greek-lower"},
      hanidays: %{
        type: :algorithmic,
        rules: "zh/SpelloutRules/spellout-numbering-days"
      },
      hans: %{type: :algorithmic, rules: "zh/SpelloutRules/spellout-cardinal"},
      hansfin: %{
        type: :algorithmic,
        rules: "zh/SpelloutRules/spellout-cardinal-financial"
      },
      ...
    }

# `default_number_system_type`

Return the default number system type name.

The default number system type is `:default`.
Note that this is not the number system itself but the type of the
number system.

## Example

    iex> Cldr.Number.System.default_number_system_type()
    :default

# `default_rbnf_rule`

Returns the default RBNF rule name for an
algorithmic number system.

### Arguments

* `system_name` is any number system name returned by
  `Cldr.known_number_systems/0` or a number system type
  returned by `Cldr.known_number_system_types/0`.

* `backend` is any `Cldr` backend. That is, any module that
  contains `use Cldr`.

### Returns

* `{:ok, {module, rule_function, locale}}` or

* `{:error, {module(), reason}}`

### Example

    iex> Cldr.Number.System.default_rbnf_rule(:taml, MyApp.Cldr)
    {:ok, {MyApp.Cldr.Rbnf.NumberSystem, :tamil, :und}}

    iex> Cldr.Number.System.default_rbnf_rule(:hebr, MyApp.Cldr)
    {:ok, {MyApp.Cldr.Rbnf.NumberSystem, :hebrew, :und}}

    iex> Cldr.Number.System.default_rbnf_rule(:jpanfin, MyApp.Cldr)
    {:ok, {MyApp.Cldr.Rbnf.Spellout, :spellout_cardinal_financial, :ja}}

    iex> Cldr.Number.System.default_rbnf_rule(:latn, MyApp.Cldr)
    {:error,
     {Cldr.UnknownNumberSystemError, "The number system :latn is not algorithmic"}}

# `generate_transliteration_map`

Generate a transliteration map between two character classes.

### Arguments

* `from` is any `String.t()` intended to represent the
  digits of a number system but that's not a requirement.

* `to` is any `String.t()` that is the same length as `from`
  intended to represent the digits of a number system.

### Returns

* A map where the keys are the graphemes in `from` and the
  values are the graphemes in `to` or

* `{:error, {exception, reason}}`

### Examples

    iex> Cldr.Number.System.generate_transliteration_map("0123456789", "9876543210")
    %{
      "0" => "9",
      "1" => "8",
      "2" => "7",
      "3" => "6",
      "4" => "5",
      "5" => "4",
      "6" => "3",
      "7" => "2",
      "8" => "1",
      "9" => "0"
    }

    iex> Cldr.Number.System.generate_transliteration_map("0123456789", "987654321")
    {:error,
     {ArgumentError, "\"0123456789\" and \"987654321\" aren't the same length"}}

# `known_number_system_types`

# `known_number_systems`

# `number_system_digits`

```elixir
@spec number_system_digits(system_name()) ::
  {:ok, String.t()} | {:error, {module(), String.t()}}
```

Returns the digits for a number system as a
string.

### Arguments

* `system_name` is any number system name returned by
  `Cldr.known_number_systems/0` or a number system type
  returned by `Cldr.known_number_system_types/0`

### Returns

* `{:ok, string_of_digits}` or

* `{:error, {exception, reason}}`.

### Examples

    iex> Cldr.Number.System.number_system_digits(:latn)
    {:ok, "0123456789"}

    iex> Cldr.Number.System.number_system_digits(:nope)
    {:error, {Cldr.UnknownNumberSystemError, "The number system :nope is not known"}}

# `number_system_digits!`

```elixir
@spec number_system_digits!(system_name()) :: String.t() | no_return()
```

Returns `digits` for a number system, or raises an exception.

### Arguments

* `system_name` is any number system name returned by
  `Cldr.known_number_systems/0` or a number system type
  returned by `Cldr.known_number_system_types/0`

### Returns

* A string of the number systems digits or

* raises an exception

### Examples

    iex> Cldr.Number.System.number_system_digits! :latn
    "0123456789"

    Cldr.Number.System.number_system_digits! :nope
    ** (Cldr.UnknownNumberSystemError) The number system :nope is not known or does not have digits

# `number_system_for`

```elixir
@spec number_system_for(Cldr.Locale.locale_reference(), system_name(), Cldr.backend()) ::
  {:ok, map()} | {:error, {module(), String.t()}}
```

Returns the actual number system from a number system type.

### Arguments

* `locale` is any valid locale name returned by `Cldr.known_locale_names/0`
  or a `Cldr.LanguageTag` struct returned by ``Cldr.Locale.new!/2``

* `system_name` is any number system name returned by
  `Cldr.known_number_systems/0` or a number system type
  returned by `Cldr.known_number_system_types/0`

* `backend` is any `Cldr` backend. That is, any module that
  contains `use Cldr`

### Returns

* `{:ok, number_system_map}` or

* `{:error, {exception, reason}}`.

### Notes

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_from_locale`

```elixir
@spec number_system_from_locale(Cldr.Locale.locale_reference()) ::
  system_name() | {:error, {module(), String.t()}}
```

Returns the number system from a language tag
or locale name.

### Arguments

* `locale` is any language tag returned be `Cldr.Locale.new/2`

### Returns

* A number system name as an atom.

### Examples

    iex> {:ok, locale} = MyApp.Cldr.validate_locale("en-US-u-nu-thai")
    iex> Cldr.Number.System.number_system_from_locale(locale)
    :thai

    iex> {:ok, locale} = MyApp.Cldr.validate_locale("en-US")
    iex> Cldr.Number.System.number_system_from_locale(locale)
    :latn

    iex> Cldr.Number.System.number_system_from_locale("ar-EG")
    :arab

# `number_system_from_locale`

```elixir
@spec number_system_from_locale(Cldr.Locale.locale_reference(), Cldr.backend()) ::
  system_name() | {:error, {module(), String.t()}}
```

Returns the default number system from a language tag
or locale name.

### Arguments

* `locale` is any language tag returned be `Cldr.Locale.new/2`
  or a locale name in the list returned by `Cldr.known_locale_names/1`

* `backend` is any `Cldr` backend. That is, any module that
  contains `use Cldr`

### Returns

* A number system name as an atom.

### Examples

    iex> Cldr.Number.System.number_system_from_locale("en-US-u-nu-thai", MyApp.Cldr)
    :thai

    iex> Cldr.Number.System.number_system_from_locale(:"en-US", MyApp.Cldr)
    :latn

# `number_system_names_for`

```elixir
@spec number_system_names_for(Cldr.Locale.locale_reference(), Cldr.backend()) ::
  {:ok, [atom()]} | {:error, {module(), String.t()}}
```

Returns the names of the number systems available for
a locale.

### Arguments

* `locale` is any locale returned by `Cldr.Locale.new!/2`.

* `backend` is any `Cldr` backend. That is, any module that
  contains `use Cldr`.

### Returns

* `{:ok, list_of_number_system_names}` or

* `{:error, {exception, reason}}`.

### Examples

    iex> Cldr.Number.System.number_system_names_for("en", TestBackend.Cldr)
    {:ok, [:latn]}

    iex> Cldr.Number.System.number_system_names_for("th", TestBackend.Cldr)
    {:ok, [:latn, :thai]}

    iex> Cldr.Number.System.number_system_names_for("he", TestBackend.Cldr)
    {:ok, [:latn, :hebr]}

    iex> Cldr.Number.System.number_system_names_for("zz", TestBackend.Cldr)
    {:error, {Cldr.InvalidLanguageError, "The language \"zz\" is invalid"}}

# `number_system_names_for!`

```elixir
@spec number_system_names_for!(Cldr.Locale.locale_reference(), Cldr.backend()) ::
  [system_name()] | no_return()
```

Returns the names of the number systems available for
a locale or raises an exception.

## Arguments

* `locale` is any valid locale name returned by `Cldr.known_locale_names/0`
  or a `Cldr.LanguageTag` struct returned by ``Cldr.Locale.new!/2``

* `backend` is any `Cldr` backend. That is, any module that
  contains `use Cldr`.

### Returns

* `list_of_number_system_names` or

* raises and exception.

## Examples

    iex> Cldr.Number.System.number_system_names_for!("en", TestBackend.Cldr)
    [:latn]

    iex> Cldr.Number.System.number_system_names_for!("th", TestBackend.Cldr)
    [:latn, :thai]

    iex> Cldr.Number.System.number_system_names_for!("he", TestBackend.Cldr)
    [:latn, :hebr]

# `number_systems`

```elixir
@spec number_systems() :: %{
  ahom: %{digits: String.t(), type: :numeric},
  tirh: %{digits: String.t(), type: :numeric},
  tols: %{digits: String.t(), type: :numeric},
  arabext: %{digits: String.t(), type: :numeric},
  arab: %{digits: String.t(), type: :numeric},
  orya: %{digits: String.t(), type: :numeric},
  armnlow: %{rules: String.t(), type: :algorithmic},
  romanlow: %{rules: String.t(), type: :algorithmic},
  beng: %{digits: String.t(), type: :numeric},
  onao: %{digits: String.t(), type: :numeric},
  mtei: %{digits: String.t(), type: :numeric},
  mymrtlng: %{digits: String.t(), type: :numeric},
  knda: %{digits: String.t(), type: :numeric},
  cakm: %{digits: String.t(), type: :numeric},
  telu: %{digits: String.t(), type: :numeric},
  rohg: %{digits: String.t(), type: :numeric},
  ethi: %{rules: String.t(), type: :algorithmic},
  hant: %{rules: String.t(), type: :algorithmic},
  gonm: %{digits: String.t(), type: :numeric},
  hanidec: %{digits: String.t(), type: :numeric},
  sunu: %{digits: String.t(), type: :numeric},
  cyrl: %{rules: String.t(), type: :algorithmic},
  tnsa: %{digits: String.t(), type: :numeric},
  latn: %{digits: String.t(), type: :numeric},
  tibt: %{digits: String.t(), type: :numeric},
  laoo: %{digits: String.t(), type: :numeric},
  grek: %{rules: String.t(), type: :algorithmic},
  fullwide: %{digits: String.t(), type: :numeric},
  gukh: %{digits: String.t(), type: :numeric},
  mroo: %{digits: String.t(), type: :numeric},
  hanidays: %{rules: String.t(), type: :algorithmic},
  sora: %{digits: String.t(), type: :numeric},
  hebr: %{rules: String.t(), type: :algorithmic},
  olck: %{digits: String.t(), type: :numeric},
  mathmono: %{digits: String.t(), type: :numeric},
  outlined: %{digits: String.t(), type: :numeric},
  tamldec: %{digits: String.t(), type: :numeric},
  mathdbl: %{digits: String.t(), type: :numeric},
  roman: %{rules: String.t(), type: :algorithmic},
  mymr: %{digits: String.t(), type: :numeric},
  mathsans: %{digits: String.t(), type: :numeric},
  hmng: %{digits: String.t(), type: :numeric},
  hansfin: %{rules: String.t(), type: :algorithmic},
  taml: %{rules: String.t(), type: :algorithmic},
  lepc: %{digits: String.t(), type: :numeric},
  osma: %{digits: String.t(), type: :numeric},
  kawi: %{digits: String.t(), type: :numeric},
  nkoo: %{digits: String.t(), type: :numeric},
  gara: %{digits: String.t(), type: :numeric},
  wcho: %{digits: String.t(), type: :numeric},
  takr: %{digits: String.t(), type: :numeric},
  talu: %{digits: String.t(), type: :numeric},
  gong: %{digits: String.t(), type: :numeric},
  deva: %{digits: String.t(), type: :numeric},
  bhks: %{digits: String.t(), type: :numeric},
  saur: %{digits: String.t(), type: :numeric},
  mymrshan: %{digits: String.t(), type: :numeric},
  cham: %{digits: String.t(), type: :numeric},
  modi: %{digits: String.t(), type: :numeric},
  mlym: %{digits: String.t(), type: :numeric},
  vaii: %{digits: String.t(), type: :numeric},
  wara: %{digits: String.t(), type: :numeric},
  sind: %{digits: String.t(), type: :numeric},
  guru: %{digits: String.t(), type: :numeric},
  armn: %{rules: String.t(), type: :algorithmic},
  diak: %{digits: String.t(), type: :numeric},
  shrd: %{digits: String.t(), type: :numeric},
  mong: %{digits: String.t(), type: :numeric},
  jpan: %{rules: String.t(), type: :algorithmic},
  lana: %{digits: String.t(), type: :numeric},
  jpanyear: %{rules: String.t(), type: :algorithmic},
  mymrepka: %{digits: String.t(), type: :numeric},
  kali: %{digits: String.t(), type: :numeric},
  hans: %{rules: String.t(), type: :algorithmic},
  lanatham: %{digits: String.t(), type: :numeric},
  sinh: %{digits: String.t(), type: :numeric},
  thai: %{digits: String.t(), type: :numeric},
  geor: %{rules: String.t(), type: :algorithmic},
  limb: %{digits: String.t(), type: :numeric},
  jpanfin: %{rules: String.t(), type: :algorithmic},
  khmr: %{digits: String.t(), type: :numeric},
  nagm: %{digits: String.t(), type: :numeric},
  sund: %{digits: String.t(), type: :numeric},
  hantfin: %{rules: String.t(), type: :algorithmic},
  bali: %{digits: String.t(), type: :numeric},
  greklow: %{rules: String.t(), type: :algorithmic},
  krai: %{digits: String.t(), type: :numeric},
  brah: %{digits: String.t(), type: :numeric},
  newa: %{digits: String.t(), type: :numeric},
  segment: %{digits: String.t(), type: :numeric},
  java: %{digits: String.t(), type: :numeric},
  mathsanb: %{digits: String.t(), type: :numeric},
  mathbold: %{digits: String.t(), type: :numeric},
  hmnp: %{digits: String.t(), type: :numeric},
  adlm: %{digits: String.t(), type: :numeric},
  mymrpao: %{digits: String.t(), type: :numeric},
  gujr: %{digits: String.t(), type: :numeric}
}
```

Return a map of all CLDR number systems and their
definitions.

## Example

    iex> Cldr.Number.System.number_systems() |> Enum.count
    97

# `number_systems_for`

```elixir
@spec number_systems_for(Cldr.Locale.locale_reference(), Cldr.backend()) ::
  {:ok, map()} | {:error, {module(), String.t()}}
```

Returns the number system types mapped to a number
system name for a locale.

When formatting a nummber it is acceptable to refer
to either the nuumber system type or the number system
name.

### Arguments

* `locale` is any valid locale name returned by `Cldr.known_locale_names/0`
  or a `Cldr.LanguageTag` struct returned by ``Cldr.Locale.new!/2``.

* `backend` is any `Cldr` backend. That is, any module that
  contains `use Cldr`.

### Returns

* `{:ok, number_system_map}` or

* `{:error, {exception, reason}}`.

### Examples

    iex> Cldr.Number.System.number_systems_for(:en)
    {:ok, %{default: :latn, native: :latn}}

    iex> Cldr.Number.System.number_systems_for(:th)
    {:ok, %{default: :latn, native: :thai}}

    iex> Cldr.Number.System.number_systems_for("zz", TestBackend.Cldr)
    {:error, {Cldr.InvalidLanguageError, "The language \"zz\" is invalid"}}

# `number_systems_for!`

```elixir
@spec number_systems_for!(Cldr.Locale.locale_reference(), Cldr.backend()) ::
  map() | no_return()
```

Returns the number system types mapped to a number
system name for a locale or raises an exception.

### Arguments

* `locale` is any valid locale name returned by `Cldr.known_locale_names/0`
  or a `Cldr.LanguageTag` struct returned by ``Cldr.Locale.new!/2``

* `backend` is any `Cldr` backend. That is, any module that
  contains `use Cldr`. The default is `Cldr.default_backend!/0`.

### Returns

* `number_system_map` or

* raises an exception.

### Examples

    iex> Cldr.Number.System.number_systems_for!("en")
    %{default: :latn, native: :latn}

    iex> Cldr.Number.System.number_systems_for!("th", TestBackend.Cldr)
    %{default: :latn, native: :thai}

# `number_systems_like`

```elixir
@spec number_systems_like(
  Cldr.Locale.locale_reference(),
  system_name(),
  Cldr.backend()
) ::
  {:ok, list()} | {:error, {module(), String.t()}}
```

Returns locale and number systems that have the same digits and
separators as the supplied one.

### Arguments

* `locale` is any valid locale name returned by `Cldr.known_locale_names/0`
  or a `Cldr.LanguageTag` struct returned by ``Cldr.Locale.new!/2``

* `system_name` is any number system name returned by
  `Cldr.known_number_systems/0` or a number system type
  returned by `Cldr.known_number_system_types/0`

* `backend` is any `Cldr` backend. That is, any module that
  contains `use Cldr`

### Returns

### Notes

* Transliterating between locale & number systems is expensive.  To avoid
  unnecessary transliteration we look for locale and number systems that have
  the same digits and separators.  Typically we are comparing to locale "en"
  and number system "latn" since this is what the number formatting routines use
  as placeholders.

### Examples

    ==> import Cldr.LanguageTag.Sigil
    ==> Cldr.Number.System.number_systems_like(:en, :latn, MyApp.Cldr)
    {:ok,
      [
        {~l[en], :latn},
        {~l[en-IN], :latn},
        {~l[ta], :latn},
        {~l[th], :latn},
        {~l[zh], :latn}
      ]
    }

# `numeric_systems`

Returns a map of the number systems that have
their own digit character representations.

See also `Cldr.Number.System.algorithmic_systems/0`.

### Example

    ==> Cldr.Number.System.numeric_systems()
    %{
      gonm: %{type: :numeric, digits: "𑵐𑵑𑵒𑵓𑵔𑵕𑵖𑵗𑵘𑵙"},
      mathdbl: %{type: :numeric, digits: "𝟘𝟙𝟚𝟛𝟜𝟝𝟞𝟟𝟠𝟡"},
      bhks: %{type: :numeric, digits: "𑱐𑱑𑱒𑱓𑱔𑱕𑱖𑱗𑱘𑱙"},
      deva: %{type: :numeric, digits: "०१२३४५६७८९"},
      adlm: %{type: :numeric, digits: "𞥐𞥑𞥒𞥓𞥔𞥕𞥖𞥗𞥘𞥙"},
      telu: %{type: :numeric, digits: "౦౧౨౩౪౫౬౭౮౯"},
      cakm: %{type: :numeric, digits: "𑄶𑄷𑄸𑄹𑄺𑄻𑄼𑄽𑄾𑄿"},
      mathsans: %{
        type: :numeric,
        digits: "𝟢𝟣𝟤𝟥𝟦𝟧𝟨𝟩𝟪𝟫"
      },
      nkoo: %{type: :numeric, digits: "߀߁߂߃߄߅߆߇߈߉"},
      ...
    }

# `system_name_from`

```elixir
@spec system_name_from(system_name(), Cldr.Locale.locale_reference(), Cldr.backend()) ::
  {:ok, atom()} | {:error, {module(), String.t()}}
```

Returns a number system name for a given locale and number
system reference.

### Arguments

* `system_name` is any number system name returned by
  `Cldr.known_number_systems/0` or a number system type
  returned by `Cldr.known_number_system_types/0`

* `locale` is any valid locale name returned by `Cldr.known_locale_names/0`
  or a `Cldr.LanguageTag` struct returned by ``Cldr.Locale.new!/2``

* `backend` is any `Cldr` backend. That is, any module that
  contains `use Cldr`.

### Returns

* `{:ok, number_system_name}` or

* `{:error, {exception, reason}}`.

### Notes

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> Cldr.Number.System.system_name_from(:default, "en", TestBackend.Cldr)
    {:ok, :latn}

    iex> Cldr.Number.System.system_name_from("latn", "en", TestBackend.Cldr)
    {:ok, :latn}

    iex> Cldr.Number.System.system_name_from(:native, "en", TestBackend.Cldr)
    {:ok, :latn}

    iex> Cldr.Number.System.system_name_from(:nope, "en", TestBackend.Cldr)
    {
      :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.

# `system_name_from!`

```elixir
@spec system_name_from!(system_name(), Cldr.Locale.locale_reference(), Cldr.backend()) ::
  atom() | no_return()
```

Returns a number system name for a given locale and number system
reference or raises an exception.

### Arguments

* `system_name` is any number system name returned by
  `Cldr.known_number_systems/0` or a number system type
  returned by `Cldr.known_number_system_types/0`

* `locale` is any valid locale name returned by `Cldr.known_locale_names/0`
  or a `Cldr.LanguageTag` struct returned by ``Cldr.Locale.new!/2``

* `backend` is any `Cldr` backend. That is, any module that
  contains `use Cldr`.

### Returns

* `number_system_name` or

* raises an exception.

### Examples

    iex> Cldr.Number.System.system_name_from!(:default, "en", TestBackend.Cldr)
    :latn

    iex> Cldr.Number.System.system_name_from!("latn", "en", TestBackend.Cldr)
    :latn

    iex> Cldr.Number.System.system_name_from!(:traditional, "he", TestBackend.Cldr)
    :hebr

# `systems_with_digits`

> This function is deprecated. Use numeric_systems/0 instead.

# `to_system`

```elixir
@spec 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 a `float`, `integer` or `Decimal`

* `system_name` is any number system name returned by
  `Cldr.known_number_systems/0` or a number system type
  returned by `Cldr.known_number_system_types/0`

* `backend` is any `Cldr` backend. That is, any module that
  contains `use 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 digits `0..9`
  into a the number system equivalent.  In this case,
` to_system/3` invokes `Cldr.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 through `Cldr.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, "壹佰贰拾叁"}

# `to_system!`

```elixir
@spec to_system!(Cldr.Math.number_or_decimal(), atom(), Cldr.backend()) ::
  binary() | no_return()
```

Converts a number into the representation of
a non-latin number system or raises an exception.

### Arguments

* `number` is a `float`, `integer` or `Decimal`

* `system_name` is any number system name returned by
  `Cldr.known_number_systems/0` or a number system type
  returned by `Cldr.known_number_system_types/0`

* `backend` is any `Cldr` backend. That is, any module that
  contains `use Cldr`

### Returns

* `string_of_digits` or

* raises an exception

See `Cldr.Number.System.to_system/3` for further
information.

### Examples

    iex> Cldr.Number.System.to_system!(123, :hans, TestBackend.Cldr)
    "一百二十三"

    iex> Cldr.Number.System.to_system!(123, :hant, TestBackend.Cldr)
    "一百二十三"

    iex> Cldr.Number.System.to_system!(123, :hansfin, TestBackend.Cldr)
    "壹佰贰拾叁"

# `unknown_number_system_for_locale_error`

Returns an error tuple for an number system unknown to a given locale.

### Arguments

* `number_system` is any number system name **not** returned by `Cldr.known_number_systems/0`

* `locale` is any valid locale name returned by `Cldr.known_locale_names/0`
  or a `Cldr.LanguageTag` struct returned by ``Cldr.Locale.new!/2``

* `valid_number_systems` is a map returned by `Cldr.Number.System.number_systems_for/2`.

### Returns

* `{Cldr.UnknownNumberSystemError, reason}`

---

*Consult [api-reference.md](api-reference.md) for complete listing*
