Solved

setprecision wrong output c++

Posted on 2006-11-13
3
613 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
  • 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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Suggested Solutions

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…
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

809 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