Login | Register   
RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.

Tip of the Day
Language: C++
Expertise: All
Jan 18, 2000



Application Security Testing: An Integral Part of DevOps

Rounding a Number Up and Down

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
Danny Kalev
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date