floor() - Mathematical Function

How is Mathematical Function "floor()" used in C++?
How to find the round down value of a number?

Explanation

floor() is a Mathematical Function that returns the largest integer that can be represented as a floating point value which is not greater then the given number "num". In other words , it returns the Round Down value of a given number.

Syntax:


float floor( float num);
double floor( double num);
long double floor( long double num);

Example :



#include <stdio.h>
#include <math.h>
int main ()
{
printf ("floor of 3.2 is %.1lf\n", floor (3.2) );
printf ("floor of 3.8 is %.1lf\n", floor (3.8) );
printf ("floor of -4.3 is %.1lf\n", floor (-4.3) );
printf ("floor of -7.7 is %.1lf\n", floor (-7.7) );
return 0;
}

Result :

floor of 3.2 is 3.0
floor of 3.8 is 3.0
floor of -4.3 is -5.0
floor of -7.7 is -8.0

In the above example floor() function is used to return the round down value of the number specified.

C++ Tutorial


Ask Questions

Ask Question