I know it's quite a silly question, but I really am finding the solution for the same. Suppose I am having a variable, db1
, with a value 4.166667, and I want to convert it to an integer with the value 5. How should I do that?
Asked
Active
Viewed 4,914 times
2

Peter Mortensen
- 30,738
- 21
- 105
- 131

Yama
- 2,649
- 3
- 31
- 63
-
http://en.wikipedia.org/wiki/Floor_and_ceiling_functions – Luigi Jan 11 '11 at 11:32
3 Answers
1
You can round it using the ceil
function found in math.h.
double notRounded = 4.1666667
int rounded = (int)ceil(notRounded);
Don't forget to #include <math.h>

DanielGibbs
- 9,910
- 11
- 76
- 121
0
See Stack Overflow question Is there a function to round a float in C or do I need to write my own?.
Objective-C works on top of C, so you can use this code.
-
I wanted to round it off to next integer value,so above function will be helpful. – Yama Jan 11 '11 at 11:43