Set the decimal point

Posted lym11248

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Set the decimal point相关的知识,希望对你有一定的参考价值。

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的主要内容,如果未能解决你的问题,请参考以下文章

HDOJ4347 The Closest M Points

PicklingError: Can't pickle <class 'decimal.Decimal'>: it's not the same object as decimal.Dec

bzoj3053 The Closest M Points

The cast to value type 'System.Decimal' failed because the materialized value is null. Eithe

带有片段着色器的 GLSL 仅渲染黑色 GL_POINTS

环境初始化 Build and Install the Apache Thrift IDL Compiler Install the Platform Development Tools(代码片段