I need to convert one
into 1
, two
into 2
and so on.
Is there a way to do this with a library or a class or anything?
I need to convert one
into 1
, two
into 2
and so on.
Is there a way to do this with a library or a class or anything?
I have just released a python module to PyPI called word2number for the exact purpose. https://github.com/akshaynagpal/w2n
Install it using:
make sure your pip is updated to the latest version.
Usage:
Thanks for the code snippet... saved me a lot of time!
I needed to handle a couple extra parsing cases, such as ordinal words ("first", "second"), hyphenated words ("one-hundred"), and hyphenated ordinal words like ("fifty-seventh"), so I added a couple lines:
Made change so that text2int(scale) will return correct conversion. Eg, text2int("hundred") => 100.
This is the c# implementation of the code in 1st answer:
If anyone is interested, I hacked up a version that maintains the rest of the string (though it may have bugs, haven't tested it too much).
Example:
There could be issues if you have, say, "$200". But, this was really rough.