how to find the closest int value of a float in c++ | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

how to find the closest int value of a float in c++

for eg if float value is 0.85 then the int value must be 1 because it is closest to 1. Any function,,help!!!😢

27th Jan 2018, 1:50 PM
Mohd Zaki
Mohd Zaki - avatar
3 Answers
+ 24
double round(double d) { return floor(d + 0.5); }
27th Jan 2018, 1:53 PM
Nithiwat
Nithiwat - avatar
27th Jan 2018, 1:53 PM
Hatsy Rei
Hatsy Rei - avatar
+ 3
ty
27th Jan 2018, 2:06 PM
Mohd Zaki
Mohd Zaki - avatar