标签:整数 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; // 效果同上
标签:整数 precision fixed nbsp 效果 span style 浮点数 作用
原文地址:https://www.cnblogs.com/hhyx/p/12376605.html