The php function sprintf does not return the exact value;
The sample code is as below:
<?php
$var1 = 10469116213008843;
echo $var1;
echo "\n";
$var2 = sprintf("%.0f", $var1);
echo $var2;
echo "\n";
?>
guess what will outcome?
on a 64bit os, it produce:
10469116213008843
10469116213008844
on a 32 bit os, it produce:
1.0469116213009E+16
10469116213008844
I am really confused, why ?
#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;
}
Some numbers are too large to be held in integers, so they are approximated using float mechanics. If you need to work with numbers of this magnitude untouched, consider using an extension like BC Math or GMP. These extensions will allow you to perform operations on very large numbers and get their full string representation to output them.