savoirfairelinux / num2words

Modules to convert numbers to words. 42 --> forty-two
GNU Lesser General Public License v2.1
820 stars 497 forks source link

Not properly converting number to text (100020 -> one thousand dollars, twenty cents) #553

Open bwala-eightfold opened 9 months ago

bwala-eightfold commented 9 months ago

Expected Behaviour

lang = en_US, Currency = USD Function used -> num2words(100020, to='currency', currency='USD', lang='en_US') 100020 -> 'one hundred thousand dollars'

Actual Behaviour

lang = en_US, Currency = USD Function used -> num2words(100020, to='currency', currency='USD', lang='en_US') 100020 -> 'one thousand dollars, twenty cents'

Mentioned above

image

Steps to reproduce

Steps are shown above

m-aciek commented 4 months ago

It looks like integers are being shifted left by two decimal places. It seems to be an undocumented feature. For floats (and decimals) there's no this behavior.

from num2words import num2words
num2words(100_020.56, to='currency')
Out[10]: 'one hundred thousand and twenty euro, fifty-six cents'
num2words(100_020.56, to='currency', currency='USD')
Out[11]: 'one hundred thousand and twenty dollars, fifty-six cents'
num2words(100_020., to='currency', currency='USD')
Out[12]: 'one hundred thousand and twenty dollars, zero cents'
num2words(100_020, to='currency', currency='USD')
Out[13]: 'one thousand dollars, twenty cents'
num2words(10_000_020, to='currency', currency='USD')
Out[14]: 'one hundred thousand dollars, twenty cents'
num2words(100_020, to='currency')
Out[15]: 'one thousand euro, twenty cents'
num2words(100_020., to='currency')
Out[16]: 'one hundred thousand and twenty euro, zero cents'from decimal import Decimal
num2words(Decimal(100_020), to='currency')
Out[18]: 'one hundred thousand and twenty euro, zero cents'

cc @szymon-borkowski