Opened 5 years ago

Closed 2 years ago

#28280 closed Bug (fixed)

numberformat.format() incorrectly formats large/tiny floats in scientific notation

Reported by: Wil Tan Owned by: Hasan Ramezani
Component: Utilities Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Tim Graham)

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)

comment:1 Changed 5 years ago by Tim Graham

Component: UncategorizedUtilities
Description: modified (diff)
Triage Stage: UnreviewedAccepted
Type: UncategorizedBug

comment:2 Changed 5 years ago by Tim Graham

Has patch: set
Patch needs improvement: set
Summary: numberformat.format does not handle scientific notation correctlynumberformat.format() incorrectly formats large/tiny floats in scientific notation

PR (with a few comments for improvement)

comment:3 Changed 5 years ago by Tim Graham <timograham@…>

In b94d99af:

Refs #28280 -- Added more tests for utils.numberformat.format().

comment:4 Changed 2 years ago by Hasan Ramezani

Owner: changed from nobody to Hasan Ramezani
Patch needs improvement: unset
Status: newassigned
Last edited 2 years ago by Mariusz Felisiak (previous) (diff)

comment:5 Changed 2 years ago by Mariusz Felisiak

Patch needs improvement: set
Version: 1.11master

comment:6 Changed 2 years ago by Hasan Ramezani

Patch needs improvement: unset

comment:7 Changed 2 years ago by Mariusz Felisiak

Triage Stage: AcceptedReady for checkin

comment:8 Changed 2 years ago by Mariusz Felisiak <felisiak.mariusz@…>

Resolution: fixed
Status: assignedclosed

In bc1c0340:

Fixed #28280 -- Prevented numberformat.format() from formatting large/tiny floats in scientific notation.

Note: See TracTickets for help on using tickets.
Back to Top