Solved

setprecision wrong output c++

Posted on 2006-11-13
3
605 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
Comment Utility
I believe you want...

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

Expert Comment

by:_iskywalker_
Comment Utility
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_
Comment Utility
oops i meant    outFile.precision(2);
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
array11 challenge 16 50
WMI, model #, retrieving information 10 85
wordlen challenge 3 46
python question 5 57
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
This is about my first experience with programming Arduino.
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…
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 …

763 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now