c++一些关于输出格式的函数

1.四舍五入

<cmath>

floor() //不大于自变量的最大整数
ceil()  //不小于自变量的最大整数
round() //四舍五入到最邻近的整数

 

2.输出位数

<iomanip>

cout << setfill('0') << setw(2) << hh;  //输出例如“02”

 

3.保留小数

<iomanip>

cout<<fixed<<setprecision(2)<<sum; //加fixed固定小数位(四舍五入),不加只固定实数位,

 

posted @ 2016-02-03 20:27  shadowhu  阅读(310)  评论(0编辑  收藏  举报