Link to home
Start Free TrialLog in
Avatar of xneo27
xneo27

asked on

setprecision wrong output c++

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?
ASKER CERTIFIED SOLUTION
Avatar of VoteyDisciple
VoteyDisciple

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of _iskywalker_
_iskywalker_

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;
oops i meant    outFile.precision(2);