PHP - number_format 因数学运算而失败

标签 php number-formatting

PHP 函数 number_format 在与数学运算一起使用时会产生奇怪的结果。

运行这个...

echo number_format(32545000 - 24343400) . '<br>';
echo number_format(32545000) - number_format(24343400);

为什么第二个给出的答案是“8”而不是正确答案?

最佳答案

number_format(32545000) 返回字符串:32,545,000

number_format(24343400) 返回字符串:24,343,400

将字符串转换为 int,您将得到:

32 - 24 = 8

关于PHP - number_format 因数学运算而失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19069565/

相关文章:

android - 在 Kotlin 中将值格式化为人类可读形式的依赖性

ios - 如何获取带小数的格式数字(XCode)

php - 如何获取数据库中存储的较大时间来扣除较小时间

javascript - 无法在 jQuery 中传递 formData 和其他参数

php - 在 OS X : getting the timezone in PHP or from a command prompt in Terminal

php - 如何从2个表中获取结果并且不显示重复项

php - 在 PHP 中将十六进制转换为 int64

java - 在 JTable 中用逗号替换点会导致错误的排序顺序

r - 如何控制 write.table() 输出中的小数位数?

php - PHP 5.6.4 中不再定义 CURLCLOSEPOLICY_LEAST_RECENTLY_USED : is it better to replace with something else or to comment out the reference?