Skip to content

Commit dbcc6ed

Browse files
authored
Docs: clarify metric prefix selection examples (#469)
1 parent 22b8da7 commit dbcc6ed

1 file changed

Lines changed: 14 additions & 5 deletions

File tree

‎src/humanize/number.py‎

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -550,11 +550,20 @@ def metric(value: float, unit: str = "", precision: int = 3) -> str:
550550
551551
```
552552
553-
The unit prefix is always chosen so that non-significant zero digits are required.
554-
i.e. `123,000` will become `123k` instead of `0.123M` and `1,230,000` will become
555-
`1.23M` instead of `1230K`. For numbers that are either too huge or too tiny to
556-
represent without resorting to either leading or trailing zeroes, it falls back to
557-
`scientific()`.
553+
The unit prefix keeps the scaled value compact, avoiding unnecessary leading or
554+
trailing zeroes. For example, `123_000` uses kilo (`k`) rather than `0.123 M`,
555+
and `1_230_000` uses mega (`M`) rather than `1230 k`:
556+
557+
```pycon
558+
>>> metric(123_000)
559+
'123 k'
560+
>>> metric(1_230_000)
561+
'1.23 M'
562+
563+
```
564+
565+
For numbers that are either too huge or too tiny to represent without resorting
566+
to either leading or trailing zeroes, it falls back to `scientific()`.
558567
```pycon
559568
>>> metric(1e40)
560569
'1.00 x 10⁴⁰'

0 commit comments

Comments
 (0)