Closed YouseYeung closed 11 years ago
When you use cout << fixed << setprecision(2)
, it will print 2 decimal places. But when you do not use fixed
, it will show 2 significant figures.
灰常感谢师兄的回复。但我还不是很明白哈,是加fixed有四舍五入,不加就只是省略掉之后的数字的意思吗?
try to run this code and you will be clear.
#include <iostream>
#include <iomanip>
int main(void) {
double a = 123.45678;
std::cout << std::setprecision(4) << a << std::endl;
std::cout << std::fixed << std::setprecision(4) << a << std::endl;
}
I got it! 3Q!
cout << fixed << setpricision(2); if it is cout << setpricision(2),the answer will be wrong.Why?