# cin 如何设置小数点输出位数？

- Link: https://www.ixiqin.com/2017/08/05/cin-output-how-to-set-up-the-decimal-digits/
- Published: 2017-08-05T06:08:55+08:00
- Author: 白宦成

C 语言可以通过设置输出时的格式来进行样式控制，而 C++ 默认没有这样的方法，我们需要
通过引入特别的库来实现 —— **iomanip**

    ```cpp
    #include<iostream>
    #include<iomanip>
    using namespace std;
    int main(){
        cout.setf(ios::fixed); // 设置余位补零
        int a;
        double PI;
        cin>>a;
        PI = 3.14159265358979323;
        cout<<setprecision(7)<< a*a*PI <<endl; // 设置小数点后输出 7 位
    }
    ```

 
