Python Forum

Full Version: is there py code to covert nums to text?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
is there anything that would do something along the lines of:

0 -> 'zero'
35 -> 'thirty five'
-20 -> 'minus twenty'
987654321987654 -> 'nine hundred eighty seven trillion six hundred fifty four billion three hundred twenty one million nine hundred eighty seven thousand six hundred fifty four'

?? :s

i have written this in C many years ago.  this is on the top of my "redo in python" stack.  a quick google gets lots of online tools and even an Excel macro but nothing in python. should i go ahead and do this? does someone else want to?
Hey Skaperen,
I found it after a quick search, this package might be what you are after:
https://pypi.python.org/pypi/inflect
There are examples on this site. Here's one, I didn't try it but it might work:

import inflect
p = inflect.engine()
words = p.number_to_words(1234)
I was going to say if there was not a library for it, and you already wrote it in C, all you would have to do is import your own C lib into python http://python-forum.org/viewtopic.php?f=25&t=621
That's a very nice link, a tutorial like this would be a great addition to this forum *thumbsup*
I was going to give the original authors time to move tutorials over themselves. If not, then ill jsut move it over soon
inflect works!

strange way to activate a function.
Cool class - works with exponents as well

>>> import inflect
>>> p = inflect.engine()
>>> p.number_to_words(725.16e10)
'seven trillion, two hundred and fifty-one billion, six hundred million point zero'
Larz60+