C++输出中怎么控制小数点后面的位数

如题所述

printf("%.3lf",x);
//需要库<cstdio>
cout<<setiosflags(ios::fixed)<<setprecision(3)<<x;
//需要库<iostream>和<iomanip>以及namespace std
//以上都是输出double x四舍五入到小数点后3位

温馨提示:内容为网友见解,仅供参考
第1个回答  2017-01-21
#include iomanip
然后用setprecision()
第2个回答  2017-01-21
#include iomanip
然后用setprecision()
相似回答