【问题标题】:Convert posted value to decimal with number_format使用 number_format 将发布的值转换为十进制
【发布时间】:2014-05-01 14:06:32
【问题描述】:

我的帖子数据中有一个数字为10,000,我想在数据库中存储为10000.00

我目前有以下:(在 Kohana)

number_format(input::post('amount'),2,'.','');

但这给了我错误:

ErrorException [ Notice ]: A non well formed numeric value encountered

因为$_POST['amount'] = 10,000

有什么建议可以解决这个问题吗?

【问题讨论】:

    标签: php decimal number-formatting


    【解决方案1】:

    逗号导致问题,您可以使用str_replace将其删除

    number_format(str_replace(',', '', input::post('amount')), 2, '.', '');
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-02-05
      • 1970-01-01
      • 2017-07-15
      • 2013-03-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多