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
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
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"
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
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
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"