As everybody knows, you have limited precision when you use printf
to output the value of a float
.
However, there is a trick to increase the accuracy in the output, as this example shows:
#include <stdio.h>
int main()
{
float f = 1318926965; /* 10 random digits */
printf("%10.f\n", f); /* prints only 8 correct digits */
printf("%10d\n", *(int*)&f); /* prints all digits correctly */
return 0;
}
and my question is, why don't people use this trick more often?