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  Professionalism Starts in Your Inbox: Keys to Presenting Your Best Self in Email
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