How to get the first digit after the decimal point of a float number in Rust

1 Answer

0 votes
fn main() {
    let f = 983.6571_f32;
    
    let first_digit_after_decimal_point = ((f.abs() * 10.0) as i32 % 10) as u32;
    
    println!("{}", first_digit_after_decimal_point);
}



      
/*
run:
  
6

*/

 



answered Oct 30, 2024 by avibootz
...