How to convert floating value to integer with exact precision like 123.3443 to 1233443?
60,088
int i = (int) (f * 10000 + 0.5);
Author by
sur
Updated on July 12, 2022Comments
-
sur almost 2 years
Sample code:
int main() { float f = 123.542; int i = (int)f; printf("%d\n",i); }
-
Tomas Pruzina about 12 yearsNot really generally helpful answer (though asker would get exactly what he asked for). It's (very) probably not what he had in mind.
-
PeterAllenWebb over 8 yearsThis will work, but assumes you know the number of decimal places you want in advance.