Reputation: 9522
I do have issues with str_replace on my webserver casting intergers to scientific number notation.
$strContent = "Yesterday was ##yesterdayTimestamp##!";
$yesterDayTimestamp = floor((time() - (24 * 3600)) / (24 * 3600)) * 24 * 3600 * 1000 ;
$strContent = str_replace("##yesterdayTimestamp##", $yesterDayTimestamp, $strContent) ;
echo $strContent;
// expected output / result on local server
// "Yesterday was 1423612800000!"
// result on remote production server
// "Yesterday was 1.4236128E+12!"
Trying to solve the problem with str()
or format_number()
seem not to work
How can I prevent php from using the scientific notation in code?
I found a solution to the question by changing the php configuration e.g.: PHP Scientific Notation Shortening. However since I'm in an hosted environment this is not as easy.
Upvotes: 0
Views: 697
Reputation: 214949
As long as there are less than 14 significant digits, printf(%f)
works fairly well:
$big = 1234567890123456;
echo $big, "\n"; # 1.2345678901235E+15
printf("%.0f\n", $big); # 1234567890123456
If you need more, consider BCMath/GMP
Upvotes: 1