码迷,mamicode.com
首页 > 其他好文 > 详细

作业题:小数点对齐,保留2为小数

时间:2017-10-17 10:00:42      阅读:94      评论:0      收藏:0      [点我收藏+]

标签:namespace   col   fixed   nbsp   set   using   man   pre   code   

#include <iostream>
#include <iomanip>
using namespace std;
//保留2位小数 
int main(){
    
    double x=123.456;
    double y=3.14159;
    double z=-3214.67;
    cout<<setiosflags(ios::fixed)<<setiosflags(ios::right)<<setprecision(2);
    cout<<setw(10)<<x<<endl;
    cout<<setw(10)<<y<<endl;
    cout<<setw(10)<<z<<endl;
    return 0;
}

 

作业题:小数点对齐,保留2为小数

标签:namespace   col   fixed   nbsp   set   using   man   pre   code   

原文地址:http://www.cnblogs.com/qingyundian/p/7679918.html

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