Why does std::setprecision(6) stream more than six digits in fixed-width mode?

喜你入骨 提交于 2019-12-04 10:05:38

In fixed-width mode the "precision" setting is used as the number of decimal places, in contrast with scientific mode where it is used as the number of significant digits. IOStreams provides no mechanism to use "precision" as the number of significant digits without using scientific mode.

There is a third mode, which in C++11 is activated with std::defaultfloat. This "default" mode is what you get if you don't set either fixed or scientific mode. You can re-activate it in C++03 by resetting the float flags with s.unsetf(std::ios_base::floatfield). This mode is a bit of a mix between scientific and some sort of "fixed without trailing zeros".

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!