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

前端 未结 4 1014
悲哀的现实
悲哀的现实 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:51

    If you want to print numbers with precision of 3 digits after decimal, just add the following thing before printing the number cout << std::setprecision(3) << desired_number. Don't forget to add #include in your code.

提交回复
热议问题