MyApp.Cldr.Number.parse

You're seeing just the function parse, go back to MyApp.Cldr.Number module for more information.
Link to this function

parse(string, options \\ [])

View Source

Parse a string locale-aware manner and return a number.

Arguments

  • string is any String.t

  • options is a keyword list of options

Options

  • :number is one of :integer, :float, :decimal or nil. The default is nil meaning that the type auto-detected as either an integer or a float.

  • :locale is any locale returned by MyApp.Cldr.known_locale_names/0 or a Cldr.LanguageTag.t. The default is MyApp.Cldr.get_locale/0.

Returns

  • A number of the requested or default type or

  • {:error, string} if no number could be determined

Notes

This function parses a string to return a number but in a locale-aware manner. It will normalise grouping characters and decimal separators, different forms of the + and - symbols that appear in Unicode and strips any _ characters that might be used for formatting in a string. It then parses the number using the Elixir standard library functions.

Examples

iex> MyApp.Cldr.Number.parse("+1.000,34", locale: "de")
{:ok, 1000.34}

iex> MyApp.Cldr.Number.parse("-1_000_000.34")
{:ok, -1000000.34}

iex> MyApp.Cldr.Number.parse("1.000", locale: "de", number: :integer)
{:ok, 1000}

iex> MyApp.Cldr.Number.parse("+1.000,34", locale: "de", number: :integer)
{:error, "+1.000,34"}