是否有标准的格式化函数或运算符进行舍入?(?)
Is there a standard formatting function or operator that will round up? (or down?)
我使用ostringstream输出一个数字到小数点后2位,如下所示
std::ostringstream ostr;
ostr << std::fixed << std::setprecision(2);
ostr << cylinderLength;
因此,如果气缸长度= 0.594,则如上所述输出0.59。
是否有一个运算符或函数可以在最后一位小数点后四舍五入?
在这种情况下,上面的示例将输出0.60。
尝试:
// Round towards +infinity (to 1 decimal place (use 100 for 2 decimal places)
ceil(double * 10) / 10
// Round towards -infinity (to 1 decimal place (use 100 for 2 decimal places)
floor(double * 10) / 10
相关文章:
- C++将浮点指针值舍入为小数位数
- Boost::posix_time::ptime舍入到给定的分钟数
- 浮点定向舍入和优化
- 为什么输出精度没有正确舍入?
- 使用设置精度时如何阻止数字向上舍入?
- 如何在使用 MPFR 时在提升多精度中设置舍入模式
- OpenCV 细分一致的 Rect2f 到 Rect2i 舍入
- C++ 中的舍入函数
- 舍入 QDecDouble 值,精度最多为两个字符
- 将大 int 转换为浮点数,而不舍入 c++
- 舍入错误检测
- 根据浮点符号对浮点进行舍入的最简单方法是什么
- 将整数舍入到另一个整数的最接近的倍数
- Sizeof 舍入到对齐方式,但编译器仍将对象放在剩余的字节中
- 避免将 Int 转换为双重类型转换舍入
- 浮点数学运算后舍入不一致
- 浮动到绳子而无需舍入
- C++长双精度格式而不舍入
- 不带逻辑运算符的舍入整数除法
- 是否有标准的格式化函数或运算符进行舍入?(?)