Page 1 of 1

Real Type Format.

Posted: Fri Aug 20, 2004 5:41 am
by _.B._
Greetings!
I'd like to know how to format Real Type numbers in C++.
If I have a number like 1.23456, how can I?:
truncate it to: 1.234
round it to: 1.235
or 1.75 expressed like 1.7500
using cout.
Also, if I have one floating number like 1.2345600E05, how can I show it like an integer 123456 using cout too?

Thanks in advance!

Posted: Fri Aug 20, 2004 4:46 pm
by Krzysztof Duleba
Include <iomanip> and try cout.setf(ios::fixed) and cout.precision(n).

Thanks!

Posted: Fri Aug 20, 2004 5:45 pm
by _.B._
Thanks Krzysztof!
I followed your suggestion, and found really useful information here:

http://www.minich.com/education/psu/cpl ... 1notes.htm

http://facultyfp.salisbury.edu/taanasta ... eamio.html

Thanks!, keep posting!