The standard <math.h> header declares the function ceil() and floor(). These function round the fractional part of a floating point number. ceil() returns the smallest integer that is no less than its argument. For example, ceil(6.3) returns 7. In contrast, floor() returns the largest integer that isn’t greater than its argument. For example, floor(6.3) returns 6. Here’s a complete example that demonstrates how these functions are used:
#include <math.h> int main() { double x = 1.4; double rounded; rounded = ceil(x); // rounded equals 2 rounded = floor(x); // rounded equals 1 }