What is the role of **std::setprecision()** without **std::fixed** in c++?

前端 未结 4 986
陌清茗
陌清茗 2021-02-04 15:52

As shown in the tutorial http://www.cplusplus.com/reference/iomanip/setprecision/

// setprecision example
#include      // std::cout, std::fixed
         


        
4条回答
  •  孤街浪徒
    2021-02-04 16:22

    Behaviour of std::setprecision() differs depending on the chosen formatting.

    std::fixed make std::setprecision() refer to how many digits are printed after the decimal point. Before you change the default formatting to std::fixed, std::defaultfloat is set, and std::setprecision() sets the total number of digits to be printed, including the ones both before and after the decimal point.

    Compare:

    http://www.cplusplus.com/reference/ios/defaultfloat/

    http://www.cplusplus.com/reference/ios/fixed/

提交回复
热议问题