【问题标题】:a non well formed numeric value encountered codeigniter php 7.* [duplicate]遇到codeigniter php 7.*的非格式正确的数值
【发布时间】:2019-05-22 21:14:51
【问题描述】:

我已将我的项目从 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"

我该如何解决这个问题?

【问题讨论】:

  • 不完全重复,因为这个问题没有具体询问number_format()

标签: php codeigniter php-7


【解决方案1】:

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

我认为您可以通过类型转换帖子值来消除错误,例如

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

【讨论】:

    猜你喜欢
    • 2015-10-08
    • 2013-05-27
    • 2010-11-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-02-15
    • 2012-07-28
    • 2014-09-18
    相关资源
    最近更新 更多