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

Set the decimal point

时间:2020-04-25 17:34:58      阅读:65      评论:0      收藏:0      [点我收藏+]

标签:ota   rod   man   fan   sage   operator   answer   end   his   

This passage is wrote to introduce the header file <iomanip>.

The basic usage of the library funcions from this header file is in the form of "."or by add function after the "<</>>" operator.

Let‘s see some forms about it:

#include <iostream>
#include <iomanip>
using namespace std;
int main(){
    int n=16;
    double f=3.1415926535;
    cout<<setbase(8)<<n<<endl;//you can set the input/output system(jin_zhi)by the setbase();
    cout<<setbase(10)<<n<<endl;
    cout<<setbase(16)<<n<<endl;//you can change the case by uppercase a->A;
    cin>>setbase(16)>>n;      //by this way you can easily transform short size input and output;
    cout<<setbase(10)<<n<<endl;     //it‘s the same if you use"dec/hex/oct";
    //set the significant digits,it will round off at the same time
   // ps.you can round off by int(n+0.5);
cout<<setprecision(2)<<f<<endl; //set the total decimal digits; cout<<fixed<<setprecision(6)<<f<<endl; //set the alignment(dui_qi_fang_shi); cout<<setw(10)<<left<<1<<endl;//set width cout<<setw(10)<<right<<1<<endl; //show the dot and zero; cout<<showpoint<<3.1200<<endl; //scientific form of numbers; //it will change the form entirely since it‘s used and I don‘t know how to turn off it...... cout<<scientific<<f<<endl; }

After you learned so much,you can practice by this question below.

S:calculate the area of the circle and output the answer in the round to seven decimal places

 

........

Let‘s forget about the code.  :D

Set the decimal point

标签:ota   rod   man   fan   sage   operator   answer   end   his   

原文地址:https://www.cnblogs.com/lym11248/p/12773540.html

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