在代码中使用C++ 11中的std::fixed和std::setprecision()函数来设置浮点数的精度。示例代码如下:
#include
int main() { double number = 12.3456789; cout << fixed << setprecision(3) << number << endl; return 0; }
在上面的例子中,使用fixed来指定小数点后保留的位数,setprecision()函数用来设置要保留的位数,因此输出为12.346。
上一篇:编译示例内核模块时出现错误
下一篇:编译时枚举-字符串-整数对