Currently, you can only specify a fixed accuracy when formatting floating point numbers:
println!("{:.2}", 1f64); // prints 1.00
println!("{:.2}", 1.125); // prints 1.13
println!("{:.2}", 1.1); // prints 1.10
I propose that .N
and .*
should be able to accept a range, indicating the minimum and maximum precision:
println!("{:.*}", 1..=2, 1f64); // prints 1.0
println!("{:.*}", 1..=2, 1.25); //prints 1.25
println!("{:.*}", 1..=2, 1.125); //prints 1.13