format_float

format_float(number: float)

A finite float as ECMAScript’s Number.prototype.toString writes it: the shortest digits that read back as the same double, in positional notation from 1e-6 up to (not including) 1e21, and in exponent notation outside that range.

>>> [format_float(x) for x in (1.5, 100.0, 1e16, 1e21, 1e-7, -0.0, 0.000001)]
['1.5', '100', '10000000000000000', '1e+21', '1e-7', '0', '0.000001']

Raises

Name Type Description
ValueError if number is NaN or infinite.