头文件 #include <iomanip>
源文件
floatvalue=324.79213;
cout << setprecision(4)<<value;
输出结果是
324.8
Cout<<fixed<<setprecision(4)<<value;
//加了fixed意味着固定点方式显示,所以这里的精度指的是小数位,输出结果为324.7921
程序源代码
// 小数点的精度问题.cpp : 定义控制台应用程序的入口点。
//
#include"stdafx.h"
#include<iostream>
#include<iomanip>
usingnamespace std;
intmain()
{
float value = 324.79213;
cout << setprecision(4) << value << endl;
cout<<fixed<< setprecision(4) << value <<endl;
getchar();
getchar();
return 0;
}
运行结果: