How to remove the dot of float number to end and create a whole int number in C

1 Answer

0 votes
#include <stdio.h>
#include <math.h>

int main()
{
	float f = 376.8713f;

	while (fabsf(f - (int)f) > 1e-2) {
		f *= 10;
	}

	int i = (int)f;
	printf("%d\n", i);

	return 0;
}

        
/*
run:
        
3768713
      
*/

 



answered Sep 2, 2019 by avibootz

Related questions

...