How to round a floating-point number to an integer in Rust

1 Answer

0 votes
fn main() {
    let mut x: f32 = 9382.4;
    let mut y = x.round() as i64;
    println!("{}", y); 
    
    x = 9382.5;
    y = x.round() as i64;
    println!("{}", y); 
}

 
 
/*
run:
 
9382
9383

*/

 



answered May 14, 2025 by avibootz
...