expression

Floating-point precision

Binary floating point approximates many decimal fractions. A larger mantissa can preserve smaller changes near a given magnitude, but representable values are still discrete. Expected stdout (not executed): false 0.30 Common mistake: Formatting a number does not change its stored value.

Formal Syntax & Structure

rust syntaxrust
f64::EPSILON; f64::MANTISSA_DIGITS

Working Example

Example Snippetrust
fn main() {    let total = 0.1_f64 + 0.2;    println!("{}", total == 0.3);    println!("{total:.2}");}
Rust Reference