Numero v0.2.0 Numero View Source

Numero cat either normalize non-english digits in strings, or convert english digits to non-english digits of your choice.

Link to this section Summary

Functions

Checks if all characters in a given string is numerical

Converts a string number to its standard english format

Converts a string number to number (Integer or Float)

Converts a string number to number (Integer or Float)

Removes non digit chars from a given string

Link to this section Functions

Link to this function is_digit_only?(str) View Source
is_digit_only?(String.t) :: boolean

Checks if all characters in a given string is numerical

Examples

iex> Numero.is_digit_only?("1234567890")
true

iex> Numero.is_digit_only?("12 34")
false

iex> Numero.is_digit_only?("a123")
false
Link to this function normalize(number_str) View Source
normalize(String.t) :: String.t

Converts a string number to its standard english format

Examples

iex> Numero.normalize("1۲3")
"123"

iex> Numero.normalize("1۲3.1۱۰")
"123.110"

iex> Numero.normalize("1۲a3.1۱۰ hello")
"12a3.110 hello"
Link to this function normalize_as_number(number_str) View Source
normalize_as_number(String.t) ::
  {:ok, Integer.t} |
  {:ok, Float.t} |
  :error

Converts a string number to number (Integer or Float)

Returns :error if input string is not in correct format.

Examples

iex> Numero.normalize_as_number("1۲3")
{:ok, 123}

iex> Numero.normalize_as_number("1۲3.1۱۰")
{:ok, 123.11}

iex> Numero.normalize_as_number("1a3.1")
:error
Link to this function normalize_as_number!(number_str) View Source
normalize_as_number!(String.t) :: Integer.t | Float.t

Converts a string number to number (Integer or Float)

Throws match error if input string is not in correct format

Examples

iex> Numero.normalize_as_number!("1۲3")
123

iex> Numero.normalize_as_number!("1۲3.1۱۰")
123.11
Link to this function remove_non_digits(str, exceptions \\ []) View Source
remove_non_digits(String.t, List.t) :: String.t

Removes non digit chars from a given string

Parameters

  • str: A given string to remove non numerical chars from
  • exceptions(optional): a list of chars to accept and dont remove. e.g.: [‘ ‘, ‘a’]

Examples

iex> Numero.remove_non_digits("0 1 2 3 4 5 6 7 8 9 abcd")
"0123456789"

iex> Numero.remove_non_digits("0 1 2 3 4 5 6 7 8 9 abcd", ['a', ' '])
"0 1 2 3 4 5 6 7 8 9 a"

iex> Numero.remove_non_digits("")
""

iex> Numero.remove_non_digits("a0b1c2.,asd(*$!@#!@9-=+)")
"0129"