Solved

precision()

Posted on 1998-12-10
10
185 Views
Last Modified: 2010-04-02
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?

PLEASE help

Thanks
0
Comment
Question by:strmtrpr
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
  • 2
10 Comments
 
LVL 1

Accepted Solution

by:
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.
hope that solves your problem.
:)
g_dutoit@hotmail.com


0
 
LVL 1

Expert Comment

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

Expert Comment

by:nietod
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Expert Comment

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

Author Comment

by:strmtrpr
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

by:nietod
ID: 1179917
That doesn"t make sense
0
 
LVL 1

Expert Comment

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

Author Comment

by:strmtrpr
ID: 1179919
I can't explain it either.
0
 
LVL 1

Expert Comment

by:The_Brain
ID: 1179920
cool name.
0
 

Author Comment

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

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
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.

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question