php str_replace 将整数转换为科学数字
php str_replace casting integer to scientific number
我的网络服务器上 str_replace 将整数转换为科学数字表示法确实存在问题。
$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!"
尝试用 str()
或 format_number()
解决问题似乎不起作用
如何防止 php 在代码中使用科学记数法?
我通过更改 php 配置找到了问题的解决方案,例如:PHP Scientific Notation Shortening。
但是,由于我在托管环境中,这并不容易。
只要有效数字少于 14 位,printf(%f)
就可以正常工作:
$big = 1234567890123456;
echo $big, "\n"; # 1.2345678901235E+15
printf("%.0f\n", $big); # 1234567890123456
如果您需要更多,请考虑 BCMath/GMP
我的网络服务器上 str_replace 将整数转换为科学数字表示法确实存在问题。
$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!"
尝试用 str()
或 format_number()
解决问题似乎不起作用
如何防止 php 在代码中使用科学记数法?
我通过更改 php 配置找到了问题的解决方案,例如:PHP Scientific Notation Shortening。 但是,由于我在托管环境中,这并不容易。
只要有效数字少于 14 位,printf(%f)
就可以正常工作:
$big = 1234567890123456;
echo $big, "\n"; # 1.2345678901235E+15
printf("%.0f\n", $big); # 1234567890123456
如果您需要更多,请考虑 BCMath/GMP