diff --git a/src/humanize/number.py b/src/humanize/number.py index 08f0cd87..77475e31 100644 --- a/src/humanize/number.py +++ b/src/humanize/number.py @@ -126,7 +126,7 @@ def intcomma(value: NumberOrString, ndigits: int | None = None) -> str: ndigits (int, None): Digits of precision for rounding after the decimal point. Returns: - str: string containing commas every three digits. + str: String containing commas every three digits. """ sep = thousands_separator() try: @@ -137,7 +137,7 @@ def intcomma(value: NumberOrString, ndigits: int | None = None) -> str: except (TypeError, ValueError): return str(value) - if ndigits: + if ndigits is not None: orig = "{0:.{1}f}".format(value, ndigits) else: orig = str(value) diff --git a/tests/test_number.py b/tests/test_number.py index 4ffa706b..86767cf6 100644 --- a/tests/test_number.py +++ b/tests/test_number.py @@ -54,6 +54,7 @@ def test_ordinal(test_input: str, expected: str) -> None: ([14308.40, 3], "14,308.400"), ([1234.5454545], "1,234.5454545"), ([1234.5454545, None], "1,234.5454545"), + ([1234.5454545, 0], "1,235"), ([1234.5454545, 1], "1,234.5"), ([1234.5454545, 2], "1,234.55"), ([1234.5454545, 3], "1,234.545"),