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

1 Answer

0 votes
#include <iostream>
#include <cmath>

int main() 
{ 
    float f = 983.6571f;
  
    int n = (int)(floor(fabs(f) * 10)) % 10;
 
    std::cout << n;
}   
        
  
        
/*
run:
        
6
      
*/

 



answered Aug 26, 2019 by avibootz
edited Oct 30, 2024 by avibootz
...