roundf
Round to integral value, regardless of rounding direction
Interface
#include <math.h>
double | round (double x) |
long | roundl (long double x) |
float | roundf (float x) |
long | lround (double x) |
long | lroundl (long double x) |
long | lroundf (float x) |
long | llround (double x) |
long | llroundl (long double x) |
long | llroundf (float x) |
Description
The round functions return the integral value nearest tox
rounding half-way cases away from zero, regardless of the current rounding direction.
The lround and llround functions return the integral value nearest to x
(rounding half-way cases away from zero, regardless of the current rounding direction) in the return formats specified. If the rounded value is outside the range of the return type, the numeric result is unspecified and the invalid floating-point exception is raised. A range error may occur if the magnitude of x
is too large.
Example:
Example -
Workings
#include <stdio.h> #include <math.h> int main(void) { for(double a=120;a<=130;a+=1.0) /* note: increments by fraction are not exact! */ printf("round of %.1lf is %.1lf\n", a/10.0, round(a/10.0)); return 0; }
Solution
round of 12.0 is 12.0 round of 12.1 is 12.0 round of 12.2 is 12.0 round of 12.3 is 12.0 round of 12.4 is 12.0 round of 12.5 is 13.0 round of 12.6 is 13.0 round of 12.7 is 13.0 round of 12.8 is 13.0 round of 12.9 is 13.0 round of 13.0 is 13.0