How to output with 3 digits after the decimal point with C++ stream?

前端 未结 4 1013
悲哀的现实
悲哀的现实 2020-12-15 20:51

Given a variable of float type, how to output it with 3 digits after the decimal point, using iostream in C++?

4条回答
  •  别那么骄傲
    2020-12-15 21:46

    This one does show "13.141"

    #include 
    #include 
    using namespace std;
    
    int main(){
        double f = 13.14159;
        cout << fixed;
        cout << setprecision(3) << f << endl;
        return 0;
    }
    

提交回复
热议问题