加入收藏 | 设为首页 | 会员中心 | 我要投稿 北几岛 (https://www.beijidao.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

php – 为什么$thousands_sep不能删除逗号?

发布时间:2021-08-28 03:44:33 所属栏目:大数据 来源: https://www.jb51.cc
导读:我有一个严重的问题.我的页面正在执行一个简单的公式来更新价格,如果该项目应该在销售. ?PHP if(isset($row_Brand['Sale'])) { $YourPrice = ($row_Brand['Sale'] * number_format($row_Recordset1['Price'], 2, '.', '')); } else { ($YourPrice = number_f

我有一个严重的问题.我的页面正在执行一个简单的公式来更新价格,如果该项目应该在销售.

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

价格是1,549.00.但是数字格式使用上面的代码使其为1.00.因此,结果就是结束了.这是一个严重的问题,我没有看到代码有任何问题.

解决方法:

问题是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, '.', '')); 
} 

(编辑:北几岛)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读