From ce8a8102e67dbc4afbfa38b44da45af23f704f93 Mon Sep 17 00:00:00 2001 From: Srs_vesta <101057653+SurajSanap@users.noreply.github.com> Date: Wed, 20 Nov 2024 16:14:28 +0530 Subject: [PATCH] Update numberformat.py This ensures that very small numbers (e.g., 1e-200) are formatted as 0.000... instead of using scientific notation. --- django/utils/numberformat.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/django/utils/numberformat.py b/django/utils/numberformat.py index cf8b2d219c..48c39ddde6 100644 --- a/django/utils/numberformat.py +++ b/django/utils/numberformat.py @@ -80,8 +80,10 @@ def format( else: int_part, dec_part = str_number, "" if decimal_pos is not None: - dec_part += "0" * (decimal_pos - len(dec_part)) - dec_part = dec_part and decimal_sep + dec_part + cutoff = Decimal("0." + "1".rjust(decimal_pos, "0")) + if abs(number) < cutoff: + # For very small numbers, represent as '0' with the specified precision + return "0" + decimal_sep + "0" * decimal_pos # grouping if use_grouping: try: