C++ floor()

Last Updated On Thursday 21st Apr 2022

std floor

The C++ floor() function returns the largest possible integer value which is less than or equal to the given argument and it takes a single argument , it is defined in <cmath> header file.

floor function

Syntax

	floor(double num);



Parameters

The floor() function takes a one argument.

• num – a floating point number can be double,float & long double

Return value

Returns the largest possible integer value which is less than or equal to num.

cpp floor

floor() prototype [As of C++ 11 standard]

	double floor(double num);
float floor(float num);
long double floor(long double num);
// for integral types
double floor(T num);



Example : C++ floor()

	#include <iostream>
#include <cmath>
using namespace std;

int main() {
double num, result;
num = 11.21;
result = floor(num);
cout << "Floor of " << num << " = " << result << endl;
num = -33.44;
result = floor(num);
cout << "Floor of " << num << " = " << result << endl;
num = 0.11;
result = floor(num);
cout << "Floor of " << num << " = " << result;
return 0;
}



Output

	Floor of 11.21 = 11
Floor of -33.44 = -34
Floor of 0.11 = 0