码迷,mamicode.com
首页 > 编程语言 > 详细

c++ 浮点数小数位

时间:2020-02-28 13:54:33      阅读:67      评论:0      收藏:0      [点我收藏+]

标签:整数   precision   fixed   nbsp   效果   span   style   浮点数   作用   

1. double f = 3.123456789;
2. cout<<f<<endl; // 输出3.12346 (包含整数和小数,且四舍五入)
3. cout<<setprecision(2)<<f<<endl; //输出3.1(包含整数和小数,共两位,且最后一位四舍五入),这条会作用到下一条去
4. cout<<fixed<<f<<endl; //输出3.123457 (仅包含小数,且四舍五入),没有上一条,则输出六位小数3.123457
5. cout<<setprecision(2)<<fixed<<f<<endl; //输出3.12 (小数2位,四舍五入)
6. cout<<fixed<<setprecision(2)<<f<<endl; // 效果同上

1. double f = 123456789;
2. cout<<f<<endl; // 输出1.23457*(10,6)(采用科学记数法变成包含整数和小数,共6位,且最后一位四舍五入)
3. cout<<setprecision(2)<<f<<endl; //输出120000000 1.2*pow(10,6)采用科学记数法,包含整数和小数,共两位,且最后一位四舍五入)<
4. cout<<fixed<<f<<endl; //输出12345689.000000(小数6位补0)
5. cout<<setprecision(2)<<fixed<<f<<endl; //输出12345689.00
6. cout<<fixed<<setprecision(2)<<f<<endl; // 效果同上

 

c++ 浮点数小数位

标签:整数   precision   fixed   nbsp   效果   span   style   浮点数   作用   

原文地址:https://www.cnblogs.com/hhyx/p/12376605.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!