1. 程式人生 > >作業題:小數點對齊,保留2為小數

作業題:小數點對齊,保留2為小數

ret fixed code cnblogs ios main right stream names

#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為小數