Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

float parameters

float parameters

float parameters

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

RE: float parameters


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


RE: float parameters

you could using the following format specifiers

cout.setf(ios::showpoint, ios::floatfield);

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++

RE: float parameters

Try  "The complete reference"  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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close