Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bug] Incorrect results for floating point numbers. p.number_to_words(0.000001) != 'one hundred and six' #226

Open
xenova opened this issue Dec 3, 2024 · 1 comment

Comments

@xenova
Copy link

xenova commented Dec 3, 2024

When converting numbers like 0.000001 to strings, python prints it as 1e-06, leading to problems with the result. For example:

>>> import inflect
>>> p = inflect.engine()
>>> p.number_to_words(0.000001)
'one hundred and six'
>>> p.number_to_words('0.000001')
'zero point zero zero zero zero zero one'
>>> 0.000001
1e-06

One approach is to use string formatting for floating point numbers:

>>> num = 0.000001
>>> str(num)
'1e-06'
>>> f'{num:f}'
'0.000001'
@xenova xenova changed the title [bug] Incorrect results for floating point numbers. p.number_to_words(0.000001) = 'one hundred and six' [bug] Incorrect results for floating point numbers. p.number_to_words(0.000001) != 'one hundred and six' Dec 3, 2024
@jaraco
Copy link
Owner

jaraco commented Dec 28, 2024

Thanks for the report. Would you be willing to work on a bugfix and regression test?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants