Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/humanize/number.py
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,7 @@ def metric(value: float, unit: str = "", precision: int = 3) -> str:
value /= 10**old_bucket
digits = int(max(0, precision - exponent % 3 - 1))
# Absorb a rounding carry (9.999 -> 10.0) by bumping the exponent.
if exponent < 30 and round(abs(value), digits) >= 10 ** (exponent % 3 + 1):
if exponent < 32 and round(abs(value), digits) >= 10 ** (exponent % 3 + 1):
exponent += 1
new_bucket = exponent // 3 * 3
value /= 10 ** (new_bucket - old_bucket)
Expand Down
4 changes: 4 additions & 0 deletions tests/test_number.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,10 @@ def test_clamp(test_args: list[typing.Any], expected: str) -> None:
([1.235e29, "A"], "124 RA"),
([2.56e-30, "V"], "2.56 qV"),
([2.596e32, "F"], "260 QF"),
([9.999e30, "W"], "10.0 QW"),
([-9.999e30, "W"], "-10.0 QW"),
([9.999e31, "W"], "100 QW"),
([9.999e32, "W"], "1000 QW"),
([1e50], "1.00 x 10⁵⁰"),
([1e-50], "1.00 x 10⁻⁵⁰"),
([-1500, "V"], "-1.50 kV"),
Expand Down