// 四舍五入
inline int round(double x)
{
return floor(0.5+x);
}
int _tmain(int argc, _TCHAR* argv[])
{
int x1 = round(5.8);
int x2 = round(-5.8);
int x3 = round(5.3);
int x4 = round(-5.3);
return 0;
}
本文提供了一个简单的四舍五入函数实现示例,通过使用floor函数配合特定的加法操作来达到四舍五入的效果,并展示了如何在主函数中调用该函数处理不同类型的浮点数。
// 四舍五入
inline int round(double x)
{
return floor(0.5+x);
}
int _tmain(int argc, _TCHAR* argv[])
{
int x1 = round(5.8);
int x2 = round(-5.8);
int x3 = round(5.3);
int x4 = round(-5.3);
return 0;
}
8205
1万+

被折叠的 条评论
为什么被折叠?