numberconverter provides two simple methods for converting between English and Integers in Go.
numberconverter.Etoi("One hundred thousand, three hundred and fifty two") // 100_352
numberconverter.Itoe(100352) // one hundred thousand three hundred fifty-two
It doesn't matter how you write your English numbers, they should parse in most cases. There is no prescribed style.
numberconverter.Etoi("Three hundred and forty two million") // 342_000_000
numberconverter.Etoi("nineteen thirty six") // 1936
numberconverter.Etoi("one hundred two hundred") // 100200
numberconverter.Etoi("three hundred, fourty two million") // 342_000_000
Methods for finding and replacing English numbers in your strings are provided.
numberconverter.FindAllEnglishNumber("Fifty five dogs. Three hundred and twenty three geese.") // {"Fifty five", "Three hundred and twenty three"}
numberconverter.EtoiReplaceAll("If we talk about dogs, I have three. Two of them live in a kennel") // "If we talk about dogs, I have 3. 2 of them live in a kennel"
Want to parse int8? No problem!
numberconverter.EtoiGeneric[int8]("Fifty five") // 55
Numbers above the given integer's maximum will produce unexpected results—be careful!
numberconverter.EtoiGeneric[int8]("Fifty hundred and fifty two million") // 0
No need to pass around an instance of a struct to use the converter. The package provides two simple methods that may be used globally.
Nourish your codebase with pure Go goodness.