vs中浮点数的输出,默认精度为6
可以用cout.precision();
设置精度
使用定点法cout.flags(cout.fixed);
,设置精度为小数点后面的数
取消定点法cout.unsetf(cout.fixed);
,将精度恢复成有效位
#include <iostream>
#include <windows.h>
int main()
{
double value = 1233.3456789;
cout << "默认:" << value << endl;
// 设置精度
cout.precision(7);
cout << "精度为7:" << value << endl;
// 使用定点法,设置精度为小数点后面的数
cout.flags(cout.fixed);
cout << "使用定点法:" << value << endl;
// 取消定点法,将精度恢复成有效位
cout.unsetf(cout.fixed);
cout << "取消定点法:" << value << endl;
return 0;
}
运行结果: