home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The C Users' Group Library 1994 August
/
wc-cdrom-cusersgrouplibrary-1994-08.iso
/
listings
/
v_11_07
/
1107104a
< prev
next >
Wrap
Text File
|
1993-05-04
|
898b
|
43 lines
// float.cpp: Format real numbers
#include <iostream.h>
main()
{
float x = 12345.6789, y = 12345;
cout << x << ' ' << y << '\n';
// Show two decimals
cout.precision(2);
cout << x << ' ' << y << '\n';
// Show trailing zeroes
cout.setf(ios::showpoint);
cout << x << ' ' << y << '\n';
// Show sign
cout.setf(ios::showpos);
cout << x << ' ' << y << '\n';
// Return sign and precision to defaults
cout.unsetf(ios::showpos);
cout.precision(0);
// Use scientific notation
cout.setf(ios::scientific,ios::floatfield);
float z = 1234567890.123456;
cout << z << '\n';
cout.setf(ios::uppercase);
cout << z << '\n';
return 0;
}
// Output
// 12345.678711 12345
// 12345.68 12345
// 12345.68 12345.00
// +12345.68 +12345.00
// 1.234568e+09
// 1.234568E+09