首页 > 编程 > C++ > 正文

C++输出单双精度数的小数点位数(如输出显示5.2365987456这样的数)

2019-11-08 03:07:13
字体:
来源:转载
供稿:网友

      今天闲来无事,敲有如下简代码:

                   double t=58.265987415322;

                   cout<<t<<endl;

               显示结果为:58.26599,查阅资料才知道

    正确操作应是这样:

      

#include <iostream>#include<iomanip>using namespace std;void main(){	double t = 2.1111111128796895;	cout << t << endl;//默认输出小数点后面5位,且第6位四舍五入	cout << setPRecision(15) << t << endl;//表示共输出15位数字	cout <<fixed<< setprecision(15) << t << endl;//表示输出小数点后面15位	system("pause");}            

              虽然简单,确实我们平时编写小程序,所不常见的。值得注意!


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表

图片精选