jaraco / jaraco/inflect

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

Open
#226 2 comments 0 reactions 1 assignee Claimed by @BBC-Esq View on GitHub
bug
Dominant language
Python
Stars
1.1k
Forks
127
PR merge metrics
No merged PRs in 30d

Description

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

```py
>>> 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:
```py
>>> num = 0.000001
>>> str(num)
'1e-06'
>>> f'{num:f}'
'0.000001'
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.