遇到格式不正确的数值 codeigniter php 7.*

a non well formed numeric value encountered 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"

我该如何解决?

可能是 $this->input->post('AmountDue') 导致了问题。函数 number_format 需要 float 数据类型作为第一个参数。 PHP 7+ 比以前的版本对数据类型更加挑剔。

我认为您可以通过对 post 值进行类型转换来消除错误,例如

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