php函数sprintf不返回确切的值;
示例代码如下:
<?php
$var1 = 10469116213008843;
echo $var1;
echo "\n";
$var2 = sprintf("%.0f", $var1);
echo $var2;
echo "\n";
?>
猜猜会有什么结果?
在64位操作系统上,它产生:
10469116213008843
10469116213008844
在32位操作系统上,它产生:
1.0469116213009E+16
10469116213008844
我真的很困惑,为什么?
#include <stdio.h>
/**
* 18456116213465313, 18456116950744489, 17705116944636053,
* 18456116950744489, 13368116212523055, 10469116213008843,
* 19986116955764391, 19591116945040018, 11882116944120195,
* 19166116210920723, 19166116210920723
*/
int main()
{
double oddVariable = 18456116213465313;
printf("%0.f\n", oddVariable);
oddVariable = 18456116213465313;
printf("%.0f\n", oddVariable);
oddVariable = 18456116213465313;
printf("%.0f\n", oddVariable);
return 0;
}