pub struct FormatFloat(pub f64);Expand description
A Display adapter that writes a float exactly as CPython’s
repr()/str() (identical for floats in Python 3): the shortest decimal
string that round-trips, switching to scientific notation when the base-10
exponent is < -4 or >= 16, and always keeping at least one fractional
digit (1.0, never 1) — 1e16 → "1e+16", 1234.5 → "1234.5",
inf/nan lowercased.
This is the default rendering for a bare f"{x}", str(x), repr(x) and
floats inside container reprs — not the format mini-language (that’s
format_float_g et al, in monty). Rust can’t do this directly: its f64 Display
never uses scientific notation (1e16 prints as 10000000000000000) and
renders NaN as "NaN".
As a Display adapter it writes straight to the caller’s sink with no
heap allocation: it borrows Rust’s shortest-digits guarantee via {:e}
into a small stack buffer (an f64 {:e} is ASCII and ≤ 24 bytes) and
re-lays-out those digits per CPython’s rules.
Tuple Fields§
§0: f64