How can I use the COUT to display DOUBLE or FLOAT values?
Thanks
Paul
How can I use the COUT to display DOUBLE or FLOAT values?
Thanks
Paul
thats a simple way to do it, you just do it like any other variable#include <iostream.h>
int main()
{
double num = 3.14;
float num2 = 3.201;
cout<<num<<" "<<num2<<endl;
return 0;
}
Paro
Is there a way to change the display so that I only see 3.1 or 3.2 from your example??
Thanks again.
Paul
look up setprecision() and other stream modifiers in your compilers online help section or the stream section of your favorite textbook/tutorial.
Two ways, either:
Or:Code:#include <iostream> #include <iomanip> using namespace std; ... cout << setiosflags( ios::fixed ) << setprecision( 1 ) << num << ' ' << num2 << endl;
Code:#include <iostream> using namespace std; ... cout.setf( ios::fixed ); cout.precision( 1 ); cout << num << ' ' << num2 << endl;
"Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
-Christopher Hitchens