0

How do i round off the number ?? for example x=0.688773 and i want x=0.689

Devang
  • 11,258
  • 13
  • 62
  • 100

1 Answers1

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