![]() |
float - cut down digts?
you know if you do float x = 12/12.0;
it'll give you x = 1.00000 now what do i do if i want to cout the result at 1.0 do I have to convert x into a string and take out "characters" or what? that just doesnt sound very sophiscated i feel there is better approach to it? |
Try this:
:
std::cout << std::setprecision(1) << x <<std::endl; |
That's fairly tedious, though. Isn't there a quicker way, aside from the C-style printf()?
|
Boost.Format offers printf() style with type-safety.
|
Quote:
:
using namespace std;and then go: :
cout << setprecision(1) << x << endl;an even easier approach is coding your own fraction printing function. |
"using namespace std;" is really for small exemplar programs and isn't really a good recommendation for robust programming of a serious nature. It introduces a lot of symbols; in a large program, you're likely to duplicate some (how many 'max' labels have you seen introduced by the coder). One alternative to always qualifying the label is to introduce just a few commonly used members, such as
:
using std::cout; |
do what dawei said. i'm drunk right now.
|
| All times are GMT -5. The time now is 1:42 AM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC