它將值四舍五入到不大於給定值的最接近的整數。
例如:
floor(8.2)=8.0;
floor(-8.8)=-9.0;
用法
假設一個數字是 'x'。語法是:
double floor(double x);
參數
x: 它是四舍五入到最接近的整數的值。
返回值
它返回舍入到不大於 x 的最接近整數的值。
例子1
讓我們看一個簡單的例子,考慮一個正值。
#include <iostream>
#include<math.h>
using namespace std;
int main()
{
float x=7.8;
std::cout << "Initial value of x is:" << x<<std::endl;
cout<<"Now, the value of x is:"<<floor(x);
return 0;
}
輸出:
Initial value of x is:7.8 Now, the value of x is:7
例子2
讓我們看一個考慮負值的簡單例子。
#include <iostream>
#include<math.h>
using namespace std;
int main()
{
float x=-10.2;
std::cout << "Initial value of x is:" << x<<std::endl;
cout<<"Now, the value of x is:"<<floor(x);
return 0;
}
輸出:
Initial value of x is:-10.2 Now, the value of x is:-11
相關用法
- C++ Math fabs()用法及代碼示例
- C++ Math fdim()用法及代碼示例
- C++ Math fma()用法及代碼示例
- C++ Math fpclassify()用法及代碼示例
- C++ Math fmin()用法及代碼示例
- C++ Math frexp()用法及代碼示例
- C++ Math fmax()用法及代碼示例
- C++ Math fmod()用法及代碼示例
- C++ Math scalbn()用法及代碼示例
- C++ Math acosh()用法及代碼示例
- C++ Math asinh()用法及代碼示例
- C++ Math isgreater()用法及代碼示例
- C++ Math islessgreater()用法及代碼示例
- C++ Math log2()用法及代碼示例
- C++ Math nearbyint()用法及代碼示例
- C++ Math tan()用法及代碼示例
- C++ Math log()用法及代碼示例
- C++ Math nextafter()用法及代碼示例
- C++ Math isfinite()用法及代碼示例
- C++ Math erfc()用法及代碼示例
注:本文由純淨天空篩選整理自 C++ Math floor()。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。