Advertisement

std::cout and floats......

Started by July 24, 2001 07:31 AM
0 comments, last by Jx 23 years, 6 months ago
How do I get "cout" to print more than 5 decimal places? cheers Jx
use "precision" or "setprecision":
  #include <iostream>#include <iomanip>using namespace std;int main (){    float f = 3.14159f;    cout << f << endl; // default precision    cout.precision (4); // change default    cout << f << endl; // print with new default    cout << setprecision (3) << f << endl; // also changes default    cout << f << endl;    return 0;}  

3.141593.1423.143.14 

This topic is closed to new replies.

Advertisement