Convert sum to word in Python
Can you help me count the number of words in Spanish? I am using the num2word library, but you can see that some decimal points were not converted correctly.
>>> from num2words import num2words
>>> num2words(9036.20)
u'nine thousand and thirty-six point two zero'
>>> num2words(9036.21)
u'nine thousand and thirty-six point two zero'
>>> num2words(9036.55)
u'nine thousand and thirty-six point five four'
>>> num2words(9036.55, lang='es')
u'nueve mil treinta y seis punto cinco cuatro'
Share your valuable experience.
+3
source to share
1 answer
As an aside: Spanish is now in public beta .
This is a known issue with num2word and the solution is to use Decimal
and convert the float value as a string
>>> from num2words import num2words
>>> from decimal import Decimal
>>> num2words(Decimal(str(9036.55)), lang='es')
>>> u'nueve mil treinta y seis punto cinco cinco'
+4
source to share