How does one round a f64 floating point number in Rust to a specified number of digits?
To add to @huon's great answer, if you want to round a floating point number for display purposes, but you don't know the precision at compile time, you can use the precision formatting syntax as follows:
fn main() {
let precision = 3;
let x = 12.34567;
println!("{:.1$}", x, precision); // prints 12.346 and works with `format!` as well
}
The documentation of std::fmt has more examples on the syntax.