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

1 Answer

0 votes
#include <stdio.h> 
#include <math.h> 
     
int main() 
{ 
	float f = 3.2871;

    int n = (int)(floor(fabs(f) * 10)) % 10;

    printf("%d", n);
       
    return 0; 
} 
     
     
     
/*
run:
     
2
   
*/

 



answered Aug 24, 2019 by avibootz
...