31
Mar
Mar
I know that i can use printf() and %2.2f and stuff like that i learned in C, but is there a special way to do so in C , where I'd use cout << [number displayed to 2 decimal places] << endl; ?
Answer:
cout << fixed << showpoint << setprecision(2);
then have your cout statement for what you want displayed.
ie:
say . . . x=12.496
cout << fixed << showpoint << setprecision(2) << endl;
cout << x << endl;
this should display 12.49
you can also do it in one statement.
cout << fixed << showpoint << setprecision(2) << x << endl;
Answer:
use setprecision as given here http://www.cplusplus.com/reference/iostr… Book Mark it-> del.icio.us | Reddit | Slashdot | Digg | Facebook | Technorati | Google | StumbleUpon | Window Live | Tailrank | Furl | Netscape | Yahoo | BlinkList
This entry was posted
on Monday, March 31st, 2008 at 4:42 am and is filed under Programming.
You can follow any responses to this entry through the RSS 2.0 feed.
You can leave a response, or TrackBack URI from your own site.