Skip to main content

format_float_display

Function format_float_display 

Source
pub fn format_float_display(value: f64) -> String
Expand description

Format an f64 float for display, collapsing decimal artifacts.

Config floats backed by f32 (temperatures, thresholds) widen to long f64 tails (0.7 becomes 0.699999988079071) once serialized to toml::Value, and ±0.1 stepper presses accumulate similar tails (0.8 becomes 0.799999988079071). When the value round-trips exactly through f32, the shorter f32 form is displayed; otherwise a value within a tiny epsilon of a 1- or 2-decimal grid shows the grid form. Genuine precision is never rounded. Display-only: the stored value is untouched.

assert_eq!(format_float_display(0.699999988079071), "0.7");
assert_eq!(format_float_display(0.799999988079071), "0.8");
assert_eq!(format_float_display(0.3333333333333333), "0.3333333333333333");