savoirfairelinux / num2words

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

Unexpected behaviour with year format when applied to years with following decimals #316

Open nmstoker opened 4 years ago

nmstoker commented 4 years ago

Expected Behaviour

num2words(1980.6, to='year') 'nineteen eighty point six'

Admittedly this is not exactly a common way of writing years and it's more that I would generally prefer the "least surprising" output in this situation rather than I am suggesting this is totally normal or commonly seen.

Actual Behaviour

num2words(1980.6, to='year')
'nineteen eighty point five nine nine nine nine nine nine nine nine nine nine nine nine zero'

Steps to reproduce

Running within a Conda environment: happens in python and ipython

Python 3.6.7 | packaged by conda-forge | (default, Nov 6 2019, 16:19:42) [GCC 7.3.0] on linux

>>> from num2words import num2words 
>>> num2words(1980.6, to='year')
'nineteen eighty point five nine nine nine nine nine nine nine nine nine nine nine nine zero'

If I get the chance to check behaviour on regular (non-Conda) python and for a more recent version (eg 3.7 or 3.8), I'll update the issue but I suspect it would still occur.

nmstoker commented 4 years ago

Interestingly this only happens in cases where a non-string numeric value is submitted. Thus it does not happen with:

num2words('1980.6', to='year')
'nineteen eighty point six'