Repository navigation
Commit 6c3a559
committed
fix(intcomma): handle scientific notation for large/small floats
Fixes #431 - intcomma() returns scientific notation for floats of 1e16 and
above (and very small floats like 1e-5), with no commas added.
Root cause: Python's repr() switches to scientific notation for floats with
magnitude >= 1e15 or <= 1e-5. The f"{value:,}" format specifier uses repr()
internally, so comma formatting is never applied to the exponent form.
Fix: When ndigits is None and the float is a whole number, format as int to
avoid trailing .0. When the float would be formatted in scientific notation,
use Decimal for a proper decimal representation before applying commas.1 parent 6ed367f commit 6c3a559
1 file changed
Lines changed: 20 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
197 | 197 | | |
198 | 198 | | |
199 | 199 | | |
200 | | - | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
201 | 220 | | |
202 | 221 | | |
203 | 222 | | |
| |||
0 commit comments