Real Type Format.

Write here if you have problems with your C++ source code

Moderator: Board moderators

Post Reply
_.B._
Experienced poster
Posts: 160
Joined: Sat Feb 07, 2004 7:50 pm
Location: Venezuela
Contact:

Real Type Format.

Post 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!
_.
Krzysztof Duleba
Guru
Posts: 584
Joined: Thu Jun 19, 2003 3:48 am
Location: Sanok, Poland
Contact:

Post by Krzysztof Duleba »

Include <iomanip> and try cout.setf(ios::fixed) and cout.precision(n).
_.B._
Experienced poster
Posts: 160
Joined: Sat Feb 07, 2004 7:50 pm
Location: Venezuela
Contact:

Thanks!

Post 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!
_.
Post Reply

Return to “C++”