Conversion Specifiers for Output

Heres what I dont understand. If I have value = 157.8926 and I want to print that value. Why does %g give 157.893 and %f give 157.892600. I thought they would give the same value since %g is supposed to use %f or %e, depending on which is shorter in character length. Since %f would be shorter, it would use %f. So why does it give different values. Example code is shown below.

int main(void)
{
double value=157.8926;

printf("Value = %f \n", value);
system("PAUSE");

return 0;
}



Help would be appreciated.
Well, you are printing a double, not a float. For doubles, you need to use %lf.
I realize that. The input is just for an example. Whether I use %lf or %f, I still get 157.892600. Does anyone know why %f gives a different value than %g (or %lf and %lg).
Topic archived. No new replies allowed.