1
0
mirror of https://github.com/django/django.git synced 2025-03-31 19:46:42 +00:00

Update numberformat.py

This ensures that very small numbers (e.g., 1e-200) are formatted as 0.000... instead of using scientific notation.
This commit is contained in:
Srs_vesta 2024-11-20 16:14:28 +05:30 committed by GitHub
parent f60d5e46e1
commit ce8a8102e6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -80,8 +80,10 @@ def format(
else: else:
int_part, dec_part = str_number, "" int_part, dec_part = str_number, ""
if decimal_pos is not None: if decimal_pos is not None:
dec_part += "0" * (decimal_pos - len(dec_part)) cutoff = Decimal("0." + "1".rjust(decimal_pos, "0"))
dec_part = dec_part and decimal_sep + dec_part if abs(number) < cutoff:
# For very small numbers, represent as '0' with the specified precision
return "0" + decimal_sep + "0" * decimal_pos
# grouping # grouping
if use_grouping: if use_grouping:
try: try: