How to turn any floating point value to integer?? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How to turn any floating point value to integer??

10.1 turns to 11 , 10.9 also to 11

9th Feb 2020, 6:49 AM
Rasul YeaBari Sun Beam
Rasul YeaBari Sun Beam - avatar
2 Answers
+ 2
You can try to break a floating point value into its integer and fractional part by using `modf` function. Will need to include <cmath> for this. http://www.cplusplus.com/reference/cmath/modf/ P.S. I wouldn't expect much about accuracy, casting floating point data into integer had long known for being rather problematic : )
9th Feb 2020, 8:25 AM
Ipang
+ 1
or by using ceil() #include<math.h > float f =10.1; int i = ceil(f); cout << i;
9th Feb 2020, 8:28 AM
Bahhaⵣ
Bahhaⵣ - avatar