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

PHP - number_format和舍入

The number_format function in PHP seems to round by default. My understanding is that this function is useful for separating every three numbers with a comma. Like 1403423 becomes 1,404,423 when using number_format.

So, if I have a large number that I want rounded to two decimal places, how can I do this and still have the commas properly displayed?

Desired behavior: 12042.529 --> 12,042.53

$a=12042.529;
echo number_format($a,2,'.',',');

近期文章

  • magento显示免费送货文本
  • 警告:sprintf()......参数太少
  • 用户在输入/文本区域中使用单引号时未处理的数据
  • Yii更改控制器登录重定向页面
  • MySQL:删除部分字符串,直到第三次到最后一次出现正斜杠
  • 如何根据PHP 5.3中另一个数组中的值对数组元素数组进行排序?
  • Mysql获取返回nil值的用户数据
  • 使用组合框类别和文本框javascript过滤
  • 当用户在登录后调用页面时,如何让Symfony忽略缓存?
  • php代码上的SQL查询空结果
  • 变量不会改变其值
  • 尝试使用SOAP获取值时未定义的属性
  • PyroCMS / Codeigniter数据库错误
  • PHP的jQuery / AJAX执行无法正常工作
  • wp_mail发送多封电子邮件
  • PHP修剪比我想要的更多
  • MYSQL 5.6.12中mysql插入查询中的错误
  • 在drupal中添加字段到屏幕“新内容类型”
  • 将字符串拆分为数组然后循环到HTML表中
  • 如何在html(来自url)中找到标签属性[关闭]

Copyright ©2022 我爱占星 All Rights Reserved.

浙ICP备2022030071号-1

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

友情链接:代码精华