Consider two floating numbers such as 128.44 and -36.72. The number 128.44 is between 128 and 129 with 128 being the lower. The number –36.72 is between –37 and –36 with –37 being the lower. The lowest but closest integer value of a number is referred to as its floor. Based on this, the floor of 128.44 is 128. The floor of –36.72 is –37.
|
In C++, to obtain the floor of a number, use the following function:
double floor(double Value);
The floor() function takes the considered value as the argument and returns the integer that is less than or equal to Value. Here is an example:
|
double Value1 = 1540.25;
double Value2 = -360.04;
cout << "The floor of " << Value1 << " is " << floor(Value1) << endl;
cout << "The floor of " << Value2 << " is " << floor(Value2) << endl;
This would produce:
The floor of 1540.25 is 1540
The floor of -360.04 is -361
Press any key to continue...
When using C++ Builder, you can use the Floor() function to find the floor of a number. The syntax of the function is:
int __fastcall Floor(Extended Value);
The Value argument of the function represents the number that is being considered. The function returns the integer that is less than or equal to Value. Here is an example:
|
Extended Value1 = 312.44;
Extended Value2 = -4002.35;
cout << "The floor of " << Value1 << " is " << Floor(Value1) << endl;
cout << "The floor of " << Value2 << " is " << Floor(Value2) << endl;
This would produce:
The floor of 312.44 is 312
The floor of -4002.35 is -4003
Press any key to continue...
|