设置C++ cout输出精度
cout.precision(5);
数字表示小数点位数
// modify precision
#include <iostream> // std::cout, std::ios
int main () {
double f = 3.14159;
std::cout.unsetf ( std::ios::floatfield ); // floatfield not set
std::cout.precision(5);
std::cout << f << '\n';
std::cout.precision(10);
std::cout << f << '\n';
std::cout.setf( std::ios::fixed, std:: ios::floatfield ); // floatfield set to fixed
std::cout << f << '\n';
return 0;
}
posted on 2019-02-09 18:22 lion_zheng 阅读(623) 评论(0) 编辑 收藏 举报