首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

C++中的Round()在哪里?

在C++中,round() 函数是一个数学函数,用于对浮点数进行四舍五入。它位于 <cmath> 头文件中。

在C++中,round() 函数的声明如下:

代码语言:cpp
复制
double round(double x);
float round(float x);
long double round(long double x);

其中,x 是要进行四舍五入的浮点数。

使用示例:

代码语言:cpp
复制
#include<iostream>
#include <cmath>

int main() {
    double num = 3.14159;
    double rounded_num = round(num);
    std::cout << "Rounded number: "<< rounded_num<< std::endl;
    return 0;
}

输出:

代码语言:txt
复制
Rounded number: 3

在这个示例中,我们使用了 <cmath> 头文件中的 round() 函数,将 3.14159 四舍五入为 3

页面内容是否对你有帮助?
有帮助
没帮助

相关·内容

领券