我已经将项目从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"
我该如何解决?
答案 0 :(得分:1)
可能是$this->input->post('AmountDue')
引起了问题。函数number_format
希望将float数据类型作为第一个参数。与以前的版本相比,PHP 7+在数据类型方面更为挑剔。
我认为您可以通过类型化发布值来摆脱错误,例如
$AmountDue = number_format( (float) $this->input->post('AmountDue'), 2, '.','');