Given this code:
let a: f64 = 0.1 + 0.2;
let b: f32 = 0.1 + 0.2;
let c: f32 = 0.30000000000000004;
let d: f32 = 0.300000012;
println!("{}", a); // 0.30000000000000004
println!("{}", b); // 0.3
println!("{}", c); // 0.3
println!("{}", d); // 0.3
Why does Rust only print the full floating point value (0.30000000000000004) for f64?
I know that in memory, variables a and b will not be exactly equal to 0.3. But I can't understand why Rust prints as it is in memory for f64, but for f32 it uses a different approach and only prints 0.3.