Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

float parameters

Status
Not open for further replies.

INDO

Programmer
Mar 18, 2001
12
US
could somebody please give me a clue as to how I can reduce the number of digits from a float when giving a write out command i.e. for a float that gives currency as an answer?

rather than 2.6799346 I would like 2.67.

many thanks
Indo
 
Try
value=2.676123456;
printf("%7.2f",value);

there are more Format specifier for integers,floats,chars,strings.....

hnd
hasso55@yahoo.com

 
you could using the following format specifiers

cout.setf(ios::showpoint, ios::floatfield);
cout.setf(ios::fixed);
cout<<setprecision(2);

any floating point output will show to 2 digits of precision.

you have to include iomanip.h for setprecision to work
the first 2 lines are taken care of by the ios class which is a base class of iostream.h used for i/o in c++
 
Try &quot;The complete reference&quot; c++ which gives idea about
the formatting of the float,string and much more.If u want u can also download the programs from the net
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top