众所周知,当你使用printf
输出float
值时,存在精度限制。
然而,有一种技巧可以增加输出的精度,下面这个例子展示了这种技巧:
#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;
}
我的问题是,为什么人们不经常使用这个技巧?