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

1 Answer

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

using namespace std;

int main() {
    float f = 376.8713f;

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

	int i = (int)f;
    
    cout << i;
}



/*
run:

3768713

*/

 



answered Sep 3, 2019 by avibootz
...