Solved

setprecision wrong output c++

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
This is about my first experience with programming Arduino.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …

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