需要包含的头文件

#include <iomanip>

Program
cout 控制数值的输出精度
Result
cout 控制数值的输出精度

Summary:

setprecision(n)设置精度为n

当没有设置fixed时,这个数的精度为n,设置fixed时,小数点后的数字精度为n,小数点前没有限制。

关于输出的精度控制见《C++ Primer(3rd edition)chapter20- iostream library

相关文章: