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

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

发布时间:2020-12-13 16:55:23 所属栏目:PHP教程 来源:网络整理
导读:我有一个严重的问题.我的页面正在执行一个简单的公式来更新价格,如果该项目应该在销售. ?php if(isset($row_Brand['Sale'])) { $YourPrice = ($row_Brand['Sale'] * number_format($row_Recordset1['Price'],2,'.','')); } else { ($YourPrice = number_form
我有一个严重的问题.我的页面正在执行一个简单的公式来更新价格,如果该项目应该在销售.

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

价格是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']),''));
} 
else 
{ 
     ($YourPrice = number_format(str_replace(','')); 
}

(编辑:李大同)

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

    推荐文章
      热点阅读