在窗口上的float中额外的0打印

Extra 0 print in float on windows

本文关键字:打印 float 窗口      更新时间:2023-10-16

我有一个程序显示不同的打印(在windows上额外的0),我试图使它与linux相同。在windows上使用Visual studio 2012。linux下使用g++ v4.8.3

有什么建议吗

我创建了一个小程序来展示我所面临的问题…

#include "stdafx.h"
#include <stdio.h>
int main()
{
 float f = -1e-14;
 printf("nn  t Lets print the float value  -1e-14  as  [%9.3g]  nnnn",f);  
return 0;
}

linux:

/home/mag>./a.out

         Lets print the float value  -1e-14  as  [   -1e-14]

在windows上:(注意-1e-014中额外的0)

         Lets print the float value  -1e-14  as  [  -1e-014]

我试图使其相同的原因是因为我正在调试windows和linux的一些输出,而windows和linux的输出之间的巨大差异是由于上述问题造成的,因此我错过了重要的差异。

首先调用_set_output_format(_TWO_DIGIT_EXPONENT),使printf()在VS2012中使用两位数指数