formatting problem

: I am using borland C++ 4.52. I need to format some output that will show a

: double to 3 digit percision

: and truncate the leading zero when there.

: I keep getting 0.999 instead of .999 . any suggestions?


: price purchase and traveled are doubles pulled in from a file where they are

: space deliniated

: i.e.

: .999 13.5 285.6

: 1.019 14 275

: 1.159 16.75 299.4

: the following is the code that will handle the printout that I am having

: trouble with.


:

: cout.setf(ios::fixed,ios::fixed); //setting the fixed float fields

: cout.setf(ios::left,ios::adjustfield); //setting the fixed float fields

: do

: {

: if (fin>>price)

: {

: fin>>purchase>>traveled;

: cout<<"
"<<setw(22)<<"Gas Price Per Gallon"<<"=<br>
: $"<<setprecision(3)<<price<<endl; //THIS IS THE LINE I NEED HELP WITH<br>
: cout<<setw(22)<<"Total Purchase Amount"<<"=<br>
: $"<<setprecision(2)<<purchase<<endl;<br>
: cout<<setw(22)<<"Total Miles Travelled"<<"=<br>
: "<<setprecision(1)<<traveled<<endl;<br>
: cout<<setw(22)<<"Miles Per Gallon"<<"=<br>
: "<<setprecision(0)<<mpg(traveled,price,purchase)<<endl;<br>
: }

: while( );





Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories