home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / lang / cplus / 18322 < prev    next >
Encoding:
Text File  |  1992-12-22  |  1.1 KB  |  49 lines

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!gatech!darwin.sura.net!convex!news.utdallas.edu!corpgate!brtph560!brtph597!markham
  3. From: markham@brtph597.bnr.ca (Andrew Markham P205)
  4. Subject: Help with floating point I/O (well, really O)
  5. Message-ID: <1992Dec22.200420.1734@brtph560.bnr.ca>
  6. Sender: news@brtph560.bnr.ca (Usenet News)
  7. Organization: BNR Inc. RTP, NC
  8. Date: Tue, 22 Dec 1992 20:04:20 GMT
  9. Lines: 38
  10.  
  11. The following C++ code:
  12.  
  13.         #include <iostream.h>
  14.         #include <iomanip.h>
  15.         
  16.         main()
  17.         {
  18.             float a = 0.1, b=0.12, c=0.123, d=0.0;
  19.         
  20.             cout << setprecision(3) << setw(6) << a << endl;
  21.             cout << setprecision(3) << setw(6) << b << endl;
  22.             cout << setprecision(3) << setw(6) << c << endl;
  23.             cout << setprecision(3) << setw(6) << d << endl;
  24.         }
  25.  
  26. Prints the following output:
  27.  
  28.         > a.out
  29.            0.1
  30.           0.12
  31.          0.123
  32.              0
  33.         >
  34.  
  35. How do I get it to print the following?
  36.  
  37.         > a.out
  38.          0.100
  39.          0.120
  40.          0.123
  41.          0.000
  42.         >
  43.  
  44. Thanks.
  45.  
  46. -- 
  47. Andrew W. Markham (markham@bnr.ca)
  48. Bell Northern Research, Inc.
  49.