C++教程
C++控制语句
C++函数
C++数组
C++指针
C++对象
C++继承
C++多态
C++抽象
C++常用
C++ STL教程
C++迭代器
C++程序

C++ Math floor()

C++ Math floor()

它将数值四舍五入为最接近的整数,该整数不大于给定值。
例如:
floor(8.2)=8.0;
floor(-8.8)=-9.0;

语法

假设数字为" x"。语法为:
double floor(double x);

参数

x : 它是四舍五入到最接近整数的值。

返回value

它返回四舍五入到不大于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  

昵称: 邮箱:
Copyright © 2022 立地货 All Rights Reserved.
备案号:京ICP备14037608号-4