How to convert float to string with 2 decimal places in Rust

1 Answer

0 votes
fn main() {
    let f = 787324.9761;
    
    let s = format!("{:.2}", f);
    
    println!("{}", s);
}




/*
run:

787324.98

*/

 



answered Feb 13, 2023 by avibootz

Related questions

2 answers 149 views
3 answers 253 views
2 answers 240 views
2 answers 207 views
2 answers 262 views
1 answer 218 views
...