A micro library for converting non-english UTF8 digits. (like ۱=1, ۲=2)
Almost all numbers defined in Unicode are support in Numero.
For more info on supported characters you can visit here
Use go get
on this repository:
$ go get -u github.com/faridgh1991/Numero-Go
On strings for strings:
result = numero.Normalize("1۲۳۰4a۳tس")
// result = "12304a3tس"
Smart numeric convert:
(Convert numbers to Integer or Float based on input string)
result, err = numero.NormalizeAsNumber("1۲۳۰4۳")
// result = 123043
// err = nil
result, err = numero.NormalizeAsNumber("1۲۳۰4۳.۴5")
// result = 123043.45
// err = nil
result, err = numero.NormalizeAsNumber("1۲a۳۰4۳.۴5")
// result = 0
// err = parsing "1۲a۳۰4۳.۴5": invalid syntax
Strip all non numeric chars from a string:
result = numero.RemoveNonDigits("12 345abs")
// result = "12345"
// Or even make exceptions for some chars like 'a' and ' ' (space)
result = numero.RemoveNonDigits("12 345bas", "a ")
// result = "12 345a"
Checking if a string is all numbers
result = numero.DigitOnly("1234567890")
// result = true
result = numero.DigitOnly("1234567890.a")
// result = false