devxlogo

Rounding a Number Up and Down

Rounding a Number Up and Down

The standard &ltmath.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  }
See also  How to Create and Deploy QR Codes Online: A Comprehensive Guide
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist