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 140 views
3 answers 228 views
2 answers 233 views
2 answers 202 views
2 answers 256 views
1 answer 206 views
...