在运行thinkphp5改造的系统时报错A non well formed numeric value encountered(遇到格式不正确的数值),结果发现原来是函数调用错误导致的。
原来代码里用的是这个函数,没有问题,后来改代码
$this->get_conversion_rate($rec->UserCountInstall,$rec->UserCountDownload), ///转换率函数 public function get_conversion_rate($num ,$den) { if ($den==0 or $num==0) { return 0; } else { return round($num/$den * 100,2)."%"; } }
后来代码改成这样
$this->get_conversion_rate($rec->UserCountInstall,$rec->UserCountDownload).'%',
运行时就报错:A non well formed numeric value encountered,后来替换成下面这个函数就ok了。
$this->get_conversion_value($rec->UserCountInstall,$rec->UserCountDownload).'%', ///转换比值函数 public function get_conversion_value($num ,$den) { if (!$den>0 or !$num>0) { return 0; } else { return round($num/$den * 100,2); } }
所以说大家在改代码时还是要仔细些,有时很多问题都是因为粗心大意造成的。
通过以上内容我们知道了完美解决php报错:A non well formed numeric value encountered的办法。感谢您访问“我爱捣鼓(www.woaidaogu.com)”网站的内容,希望对大家有所帮助!引用本文内容时,请注明出处!谢谢合作!