Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix intcomma with ndigits=0 #26

Merged
merged 1 commit into from Jun 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/humanize/number.py
Expand Up @@ -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:
Expand All @@ -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)
Expand Down
1 change: 1 addition & 0 deletions tests/test_number.py
Expand Up @@ -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"),
Expand Down