How do I limit a float variable to two decimal points?
I have tried static_cast and setprecision, but none of them are working for me.
Thanks for any help.
Decimal Point Precision in C++?
#include %26lt;iostream.h%26gt;
#include %26lt;iomanip.h%26gt;
void main()
{
int i = 1499;
int j = 618;
int k = 2;
float a = 34.87432;
cout %26lt;%26lt; setw(10) %26lt;%26lt; i %26lt;%26lt; setw(10) %26lt;%26lt; j %26lt;%26lt; setw(10) %26lt;%26lt; k %26lt;%26lt; endl;
cout %26lt;%26lt; setw(10) %26lt;%26lt; k %26lt;%26lt; setw(10) %26lt;%26lt; i %26lt;%26lt; setw(10) %26lt;%26lt; j %26lt;%26lt; endl;
cout %26lt;%26lt; setprecision(3) %26lt;%26lt; setw(10) %26lt;%26lt; a %26lt;%26lt; endl;
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment