摘自MSDN:SMANIP( int ) setprecision( int np );#include <iomanip.h>ParameternpAn integer that indicates the number of significant digits or significant decimal digits to be used for floating-point display.ResThis parameterized manipulator sets the stream’s internal floating-point precision variable to np. The default precision is six digits. If the display format is scientific or fixed, then the precision indicates the number of digits after the decimal point. If the format is automatic (neither floating point nor fixed), then the precision indicates the total number of significant digits. This setting remains in effect until the next change.
解决方案 »
- 如何改变CListCtrl的高亮选择背景颜色和字体颜色
- CListCtrl鼠标悬停问题
- QueueUserWorkItem为什么在vc6下不能编译通过?
- ZT:大家去下载Visual Studio Service Pack 6 !
- CAsyncSocket类在使用Send时怎样知道缓冲区已经全部发送成功?
- 求大神帮帮忙啊,在线等,一段代码看不懂 windows/openGL
- 关于控件的问题
- 如何显示一个文件夹中很多图片的缩略图
- 请问MouseStatus.cpp(10) : fatal error C1010: unexpected end of file while looking for precompiled header directive.是什么错误?谢谢。
- 如何读取二进制文件,并读取特定内容
- 有C语言的基础,以前用delphi做数据库,现想学Visual c++,请大家推荐几本好书啊。下载网址也行,谢谢。
- 怎样将整个客户区的视口保存为DIB的BMP文件?
#include <iomanip.h>void main()
{
double values[] = { 1.23, 35.36, 653.7, 4358.24 };
char *names[] = { "Zoot", "Jimmy", "Al", "Stan" };
for( int i = 0; i < 4; i++ )
cout << setw( 6 ) << names[i]
<< setw( 10 ) << values[i] << endl;
}
输出为:
Zoot 1.23
Jimmy 35.36
Al 653.7
Stan 4358.24对输出部分做修改:
for ( int i = 0; i < 4; i++ )
cout << setiosflags( ios::left )
<< setw( 6 )
<< names[i]
<< resetiosflags( ios::left )
<< setw( 10 )
<< setprecision( 1 )
<< values[i]
<< endl;
输出为:
Zoot 1
Jimmy 4e+001
Al 7e+002
Stan 4e+003
此时,输出部分的整数部分精度已经设为了1在for之前加上
cout << setiosflags( ios::fixed );
则输出变为:
Zoot 1.2
Jimmy 35.4
Al 653.7
Stan 4358.2如果将ios::fixed 变为 ios::scientific 输出为:
Zoot 1.2e+000
Jimmy 3.5e+001
Al 6.5e+002
Stan 4.4e+003