How do i round off the number ?? for example x=0.688773 and i want x=0.689
Asked
Active
Viewed 649 times
0
-
7 questions asked and how many accepted? Tsk, tsk. – Eric Brotto Mar 18 '11 at 15:31
-
possible duplicate of [Round the nearest number](http://stackoverflow.com/questions/5243437/round-the-nearest-number) – Monolo Aug 15 '12 at 09:38
1 Answers
2
What kind of number is it? If it's a float, then you can say:
myFloat = roundf(1000 * myFloat) / 1000.0;
If it's a double, use the round() function instead.

Caleb
- 124,013
- 19
- 183
- 272
-
Found this on SO, that shows examples of floor(), or ceil() http://stackoverflow.com/questions/1343890/rounding-number-to-2-decimal-places-in-c/1344261#1344261 – markhunte Mar 18 '11 at 11:10