我爱占星网 我爱占星网
首页
编程
java
php
前端
首页 编程 java php 前端

number_format返回错误的值?

This is my code:

$subTotal = number_format($subTotal, 2);

In $subTotal I had a value like 1,233.00 as a string. The return value was 1.00, which of course is wrong. So I tried something else:

$subTotal = number_format($subTotal, 2, '.', ',');

Result is still the same. How can I make it work with a , as thousand separator?

Thanks!

Remove the commas before you call number_format()

$subTotal = number_format(str_replace(',', '', $subTotal), 2);

近期文章

  • 何使用preg_match_all查找具有特定开头和特定结尾的字符串?-PHP
  • PHP:使用绝对路径在include / require文件中定义的变量不可访问
  • str_replace问题,PHP 5.2中的字符“<”和“>”
  • 在yii中更改其他字段时更改密码
  • 带有标题和XML内容的PHP帖子
  • 如果用户meta是空白回音的东西?
  • LIKE运算符中的多个条件
  • 使用Twitter json feed中的display_url
  • 做自定义用户布局的最佳方式
  • Laravel在视图中获取Collection对象
  • 从PHP中的SimpleXMLElement访问值
  • 从URL中删除文件夹名称
  • 将模块集成到yii项目中[关闭]
  • 为什么债券会导致mysql?
  • 在php中同步管理员和客户端时间的最佳方法
  • 如何使用codeigniter在mysql中插入多个复选框值
  • 将php表单插入mysql数据库时如何修复错误
  • 将MySQL数据库中的信息显示为html表
  • 什么是PHP模板中的twig模板表单action = {{path('page')}}的等价物
  • 在Laravel中过滤多个DB列的好方法

Copyright ©2022 我爱占星 All Rights Reserved.

浙ICP备2022030071号-1

部分图文来自网络,如有侵犯您的版权,请告诉我们删除

友情链接:代码精华