如何在输出控制台中显示更多小数?
问题描述:
我想输出全精度的double值。但是,使用cout函数时,即使精度为15-16位左右,它也只显示前6位数字。
I want to output the value of a double in it's full precision. However, when using the cout function, it only displays the first 6 digits even though there is around 15-16 digits of precision.
如何让我的程序显示整个值,包括幅度(幂)分量?
How do I get my program to display the entire value, including the magnitude (power) component?
答
使用 setprecision()
机械手:
http://www.cplusplus.com/reference/iostream/manipulators/setprecision/
您也可以使用 scientific
机械手来强制使用科学计数法:
You can also force scientific notation with the scientific
manipulator:
http://www.cplusplus.com/reference/iostream/manipulators/scientific/
cout << scientific << setprecision(15) << my_number << endl;