php codeigniter遇到非格式正确的数值ph​​p 7。*

时间:2018-12-23 03:39:17

标签: php codeigniter php-7

我已经将项目从PHP 5.6升级到PHP 7. *

我遇到了格式错误的数值。

$AmountDue      = number_format($this->input->post('AmountDue'), 2, '.','');
$AmountPaid     = number_format($this->input->post('AmountPaid'), 2, '.','');

我试图var_dump()这些函数的值

这是结果。

string(4) "1.16" 
string(7) "1479.75"

我该如何解决?

1 个答案:

答案 0 :(得分:1)

可能是$this->input->post('AmountDue')引起了问题。函数number_format希望将float数据类型作为第一个参数。与以前的版本相比,PHP 7+在数据类型方面更为挑剔。

我认为您可以通过类型化发布值来摆脱错误,例如

$AmountDue = number_format( (float) $this->input->post('AmountDue'), 2, '.','');