Default precision of cout is 6. For higher precision(say 10) use cout<<std::setprecision(10)<<value;
setprecision function is in iomanip header.
However if you have something like cout<<setprecision(1)<<4.0+4.0;
You will get output as 8 and not 8.0.
To get that use std::fixed.
cout<<fixed<<setprecision(1)<<4.0+4.0; gives 8.0
setprecision function is in iomanip header.
However if you have something like cout<<setprecision(1)<<4.0+4.0;
You will get output as 8 and not 8.0.
To get that use std::fixed.
cout<<fixed<<setprecision(1)<<4.0+4.0; gives 8.0
No comments:
Post a Comment