In my rust code I have a function which takes a float and precision as args. The function should return the formatted string. However, I am not sure how I can format with dynamic precision,
fn convert(val: f32, precision: i16) -> String {
format!("{:.2}", val) // The 2 should be replaced with precision
}
// convert(1.2345, 1) -> 1.2
// convert(1.2345, 2) -> 1.23