MAG MAG - 5 months ago 12
Linux Question

Extra 0 print in float on windows

I have a program which shows a different print (an extra 0 on windows) and i am trying to make it same as linux .
On windows using Visual studio 2012 . On linux using g++ v4.8.3

Any sugegstion .

I have created a small program to showcase problem that I am facing ...

#include "stdafx.h"

#include <stdio.h>

int main()
{

float f = -1e-14;
printf("\n\n \t Lets print the float value -1e-14 as [%9.3g] \n\n\n\n",f);

return 0;
}


On linux :

/home/mag>./a.out


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


On windows :(notice extra 0 in -1e-014)

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


Reason why I am trying to make it same is because I am debugging some output from windows and linux and huge amount of differences between outputs of windows and linux are due to the problem stated above and I am missing important differences because of these .

Answer

Call _set_output_format(_TWO_DIGIT_EXPONENT) first to cause printf() to use two-digit exponents with VS2012.