Solved

setprecision wrong output c++

Posted on 2006-11-13
3
619 Views
Last Modified: 2008-03-04
Heres my code:
outFile << left << setw(12) << database.Record1.id
                  << setw(20) << database.Record1.lastAmount
                  << setw(15) << database.Record1.transCount
            << "$" << setprecision(2) << database.Record1.total << endl;

database.Record1.total is a double and i want it to output like $90.77


this is what I get:
300         30.77               3              $91


does anyone know why this happens?
0
Comment
Question by:xneo27
[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
  • 2
3 Comments
 
LVL 19

Accepted Solution

by:
VoteyDisciple earned 500 total points
ID: 17930609
I believe you want...

...
<< fixed << setprecision(2) << database.Record1.total << endl;
0
 
LVL 6

Expert Comment

by:_iskywalker_
ID: 17930815
or:

outFile << left << setw(12) << database.Record1.id
               << setw(20) << database.Record1.lastAmount
               << setw(15) << database.Record1.transCount ;
  outFile.precision(5);
outFile  << "$" << setprecision(2) << database.Record1.total << endl;
0
 
LVL 6

Expert Comment

by:_iskywalker_
ID: 17930819
oops i meant    outFile.precision(2);
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone 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

In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

734 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