doujia7094 2015-10-23 03:10
浏览 99

PHP5.3 number_format返回NaN

I have this piece code developed in PHP5.5 without any issue. However, when same code is moved to another server in PHP5.3, the number_format() does not return expected value, but return "nan"

This is my code:

number_format($num, 2, ".", ",");

the variable $num is retrieved from database with data type decimal(25,8)

What confuse me is that it works for some number, but not some others. Example:

$num = 1800.00000000
number_format($num, 2, ".", ",") ==> returns "nan"

$num = 1000.00000000
number_format($num, 2, ".", ",") ==> returns "1,000.00"

Is this a common bug in PHP 5.3? Is there any solution for it?

I have google but there is no solution that works for my case so far. The typecast to float or floatval() also not working.

UPDATE

The issue happen because of DateTime::diff() that is run just before the number_format line.

Somehow this function causes issue in PHP5.3 but not in PHP5.5

Once the function is changed by using strtotime() to calculate the difference between 2 dates, everything works normal.

Although, truthfully, i still don't know why the issue happen in the first place. If anyone know about this, please share with me too. Thanks!

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 微信会员卡接入微信支付商户号收款
    • ¥15 如何获取烟草零售终端数据
    • ¥15 数学建模招标中位数问题
    • ¥15 phython路径名过长报错 不知道什么问题
    • ¥15 深度学习中模型转换该怎么实现
    • ¥15 HLs设计手写数字识别程序编译通不过
    • ¥15 Stata外部命令安装问题求帮助!
    • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
    • ¥15 TYPCE母转母,插入认方向
    • ¥15 如何用python向钉钉机器人发送可以放大的图片?