![]() |
VOOZH | about |
C++ provides floor() and ceil() functions, defined in the <cmath> header file, to find the rounded-down and rounded-up values of floating-point numbers
floor() function takes floating point number as input and returns the largest integer that is smaller than or equal to the value passed as the argument.
Syntax:
Example:
Floor of 2.3 is : 2 Floor of -2.3 is : -3
ceil() function in C++ returns the smallest integer that is greater than or equal to the value passed as the input argument.
Syntax:
Example:
Ceil of 2.3 is : 3 Ceil of -2.3 is : -2
The ceil and floor functions are important for rounding numbers. Let us see the differences between ceil() and floor() functions in tabular form:
S.No | ceil() Function | floor() Function |
|---|---|---|
1. | It is used to return the smallest integral value n that is not less than n. | It is used to return the largest integral value n that is not greater than n. |
2. | It rounds the n upwards. | It rounds the n downwards. |
3. | Its syntax is -: data_type ceil (n); | Its syntax is -: data_type floor (n); |