How to add trailing zeros to integers?

Jan 26, 2014 at 9:20pm
Got it working, thanks everyone!
Last edited on Jan 26, 2014 at 10:20pm
Jan 26, 2014 at 9:25pm
Jan 26, 2014 at 9:29pm
Round it, cast it to an integer, then print it out followed by the string ".00".

Or does that not work for you?
Jan 26, 2014 at 9:45pm
You already figured out how to round.

1
2
3
4
int round( double value )
{
    return( static_cast<int>( value + 0.5 ) );
}


And to output following 0's you can simply put a string as double main suggested

 
out << list2[i] << ".00" << endl;
Jan 26, 2014 at 10:00pm
I tried exactly what you guys suggested, but as soon as I put the ".00" in, my output only shows the first number being written; everything else is skipped.

If I take the ".00" out, everything works fine but of course without the decimal and trailing 0's.
Jan 26, 2014 at 10:08pm
Never mind, it's writing correctly, it's the reading part that isn't correct. I'll fix that.

Thank you very much everyone.
Jan 26, 2014 at 10:20pm
giblit you are right.
Last edited on Jan 26, 2014 at 11:28pm
Jan 26, 2014 at 10:58pm
He wants to output the rounded value though yours will not round alee. Also why should he not do it that way?
Topic archived. No new replies allowed.