numberformat.format() incorrectly formats large/tiny floats in scientific notation
For floats with values larger than 1e16 or smaller than 1e-5, their string representation uses scientific notation in Python, which causes numberformat.format
to return an erroneous output.
>>> from django.utils.numberformat import format
>>> format(0.0000000000000000009, '.', 2)
'9e-19.00'
>>> format(1e16, '.', 2, thousand_sep=',', grouping=3, force_grouping=True)
'1e,+16.00'
This is similar to #23935 but that was only fixed for Decimal types.
Change History (8)
Component: |
Uncategorized →
Utilities
|
Description: |
modified (diff)
|
Triage Stage: |
Unreviewed →
Accepted
|
Type: |
Uncategorized →
Bug
|
Has patch: |
set
|
Patch needs improvement: |
set
|
Summary: |
numberformat.format does not handle scientific notation correctly →
numberformat.format() incorrectly formats large/tiny floats in scientific notation
|
Owner: |
changed from nobody to Hasan Ramezani
|
Patch needs improvement: |
unset
|
Status: |
new →
assigned
|
Patch needs improvement: |
set
|
Version: |
1.11 →
master
|
Patch needs improvement: |
unset
|
Triage Stage: |
Accepted →
Ready for checkin
|
Resolution: |
→ fixed
|
Status: |
assigned →
closed
|
PR (with a few comments for improvement)