How do i get a number to display only two decimal points? I'm using a float variable, and i know that it's default is 6 decimal spots. Is there a way to change this? or a new variable type?
How do i get a number to display only two decimal points? I'm using a float variable, and i know that it's default is 6 decimal spots. Is there a way to change this? or a new variable type?
Code:float f = 0.333; cout.setprecision( 2 ); cout<<f<<endl; //Should output 0.33
Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah
You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie
i get the following error:
i've inly included the following:error C2039: 'setprecision' : is not a member of 'ostream_withassign'
#include <iostream.h>
#include <string.h>
#include <stdlib.h>
aha, i got it, its "precision" w/o the "set". thanks.
Try this...
... this should work. setprecision() is the ANSI standard manipulator. I suspect it failed in your setup because you are using the old style headers, (those with .h on them), and not the standard compliant ones declared in namespace std.Code:#include <iostream> #include <iomanip> using namespace std; ... ... cout << setprecision(2);
If you try this and it fails, tell me what compiler you are using.
Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.
>>#include <iomanip>
This was the missing item causing the problem. It's where setprecision lives.
When all else fails, read the instructions.
If you're posting code, use code tags: [code] /* insert code here */ [/code]