Solved

# precision()

Posted on 1998-12-10
181 Views
I have a little problem:
in a method I have

cout.setf(ios::showpoint);
cout.precision(2);
cout<<number<<endl;

coutn<<number2<<endl; // this is the problem

this doesn't output number2 .

but if I take out precision(); it outputs just fine

what am I overlooking?

Thanks
0
Question by:strmtrpr
• 5
• 3
• 2

LVL 1

Accepted Solution

The_Brain earned 20 total points
ID: 1179912
it is suppose to be.

cout.setprecision(2); //set two dec points
cout.setf(ios::fixed); //ENSURES it.
cout.setf(ios::showpoint);

in that order, other wise it is temporary.  :) I think, but the
above order is correct.  first how many, then permanent, the show the point.
:)
g_dutoit@hotmail.com

0

LVL 1

Expert Comment

ID: 1179913
sorry, it is cout.precision(2) NOT setprecision. SORRY. typo
0

LVL 22

Expert Comment

ID: 1179914
The order should not matter.  (At least as far as I know.)

you say "this doesn't output number2 . "  Does that mean it doesn't ouput it all?  or do you mean it doesn't ouput it the way you want it.  If so, what do you get and what do you want?
0

LVL 1

Expert Comment

ID: 1179915
Sorry, true, very true.  It doesn't matter.  but to me it does :)
0

Author Comment

ID: 1179916
it outputs a  hex looking number.

I tried in the order that THE_BRAIN suggested and it worked fine

thanks for the help.
0

LVL 22

Expert Comment

ID: 1179917
That doesn"t make sense
0

LVL 1

Expert Comment

ID: 1179918
it doesn't make sense, does it? :)
0

Author Comment

ID: 1179919
I can't explain it either.
0

LVL 1

Expert Comment

ID: 1179920
cool name.
0

Author Comment

ID: 1179921
I can't explain it either.
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

### Suggested Solutions

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generatâ€¦
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticallâ€¦
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor anâ€¦
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.