【问题标题】:Why doesn't $thousands_sep work to remove comma?为什么 $thousands_sep 不能删除逗号?
【发布时间】:2015-04-03 09:34:40
【问题描述】:

我有一个严重的问题。如果商品应该打折,我的页面正在执行一个简单的公式来更新价格。

<?php if(isset($row_Brand['Sale'])) 
      { 
         $YourPrice = ($row_Brand['Sale'] * number_format($row_Recordset1['Price'], 2, '.', ''));
      } 
      else 
      { 
         ($YourPrice = number_format($row_Recordset1['Price'], 2, '.', '')); 
      } 
  ?>

Price 的值为 1,549.00。但是,数字格式使用上面的代码使其变为 1.00。因此,结果是遥遥无期。这是一个严重的问题,我看不出代码有什么问题。

【问题讨论】:

    标签: php number-formatting


    【解决方案1】:

    问题是number_format() 无法解析带有逗号的数字。您可以使用str_replace(',', '', $row_Recordset1['Price']) 解决此问题,然后在号码上执行number_format()

    if(isset($row_Brand['Sale'])) 
    { 
         $YourPrice = ($row_Brand['Sale'] * number_format(str_replace(',', '', $row_Recordset1['Price']), 2, '.', ''));
    } 
    else 
    { 
         ($YourPrice = number_format(str_replace(',', '', $row_Recordset1['Price']), 2, '.', '')); 
    } 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-04-15
      • 1970-01-01
      • 1970-01-01
      • 2015-09-13
      • 2016-04-10
      • 1970-01-01
      相关资源
      最近更新 更多