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 288 views
3 answers 421 views
2 answers 368 views
2 answers 356 views
2 answers 408 views
1 answer 306 views
...