Precision and Decimal Places in iostreams

 








  PRODUCT  :  C++                                    NUMBER  :  640

  VERSION  :  All

       OS  :  PC DOS

     DATE  :  August 12, 1992                          PAGE  :  1/1


    TITLE  :  Precision and Decimal Places in iostreams





  Given a real variable  x  (either float or double) with value 2.0

  and also given a real variable PI = 3.1415926...


  ---- OUTPUT ----   ------------- STATEMENT ---------------


  "x == 2"             cout<<"x == "<<x;


  "x==2.00"            cout<<setprecision(3)

                           <<setiosflags(ios::showpoint)

                           <<"x == "<<x;


  "x == "02.0"         cout<<setw(4)<<setfill('0')

                           <<setprecision(2)

                           <<"x == "<<x;


  "pi == 3.14"         cout<<setprecision(3)<<"pi == "<<pi;


  "pi == 3.1416"       cout<<setprecision(5)<<"pi == "<<pi;


  DISCLAIMER: You  have the right to use this technical information

  subject to the terms  of  the  No-Nonsense License Statement that

  you received with  the  Borland product to which this information

  pertains.



























Comments

Popular posts from this blog

PHILEMON

War of the World TV series