cout格式化输出
来源:互联网 发布:广电总局网络主播新规 编辑:程序博客网 时间:2024/06/07 02:01
1.小数位数
可以使用setprecision()来确定小数位数,加fixed补充末位的0
需要添加头文件
#include<iomanip>
假设 ans=1.202;
以下是保留两位小数,若末尾是0,则省略
cout << setprecision(2) << ans <<endl;//输出1.2
若想不省略末尾的0,则需要加上fixed
cout.setf(ios::fixed);cout << fixed << setprecision(2) << ans << endl;//输出1.20
若想恢复省略
cout.unsetf(ios::fixed); cout << setprecision(2) << ans <<endl;//输出1.2
1 0
- cout 格式化输出
- cout格式化输出示例
- cout格式化输出
- cout格式化输出 详解
- cout 格式化输出
- cout 格式化输出
- cout 格式化输出
- cout的格式化输出
- cout 格式化输出详解
- cout 格式化输出详解
- cout的格式化输出
- cout 格式化输出
- cout格式化输出
- cout格式化输出
- cout 格式化输出
- cout 格式化输出
- C++ cout格式化输出
- cout格式化输出
- Cocos2d-x SpriteFrameCache的使用
- 集合框架_TreeSet的add()方法源码再次解读和TreeSet对元素排序的总结
- c控制语句:循环(1)
- 插入排序—希尔排序(Shell`s Sort)
- BZOJ3685 普通van Emde Boas树
- cout格式化输出
- c项目3
- 产品与运营之应用商店推广的整体流程
- Redis之Zset
- C#利用反射获取对象属性值
- 【LeetCode】104. Maximum Depth of Binary Tree
- 消费者本地事务
- CSS 背景的颜色的线性渐变
- 数据结构 12 连续存储数组的算法演示