Section 18.9 Rounding in C
C supports several functions to help with rounding (such as rounding up, rounding down, just rounding, etc). You need to
#include <math.h>
in order to use them. Here are some of the functions at your disposal:
Function | Prototype | Description |
floor() |
double floor(double x); |
Returns the nearest integer which is less than or equal to the argument passed to this function.
|
round() |
double round (double x); |
Returns the nearest integer value of the argument passed to this function.
|
lround() |
long lround (double x); |
Returns the nearest integer value of the argument passed to this function.
|
ceil() |
double ceil (double x); |
Returns the nearest integer value which is greater than or equal to the argument passed to this function.
|