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

在PHP中格式化圆形值2小数

Have to round the number in php. I have tried like below,

round(12.4569,2);

it will return 12.46. its OK.

But, round(12.4003,2);

the output is 12.4

But need the output 12.40

suggestion please...

Use number_format :

number_format((float)$number, 2, '.', '');

The solution using sprintf function:

print_r(sprintf("%.2f",12.4003,2));   // 12.40
print_r(sprintf("%.2f",12.4569,2));   // 12.46

http://php.net/manual/en/function.sprintf.php

Try using this in ur code :

number_format(12.4003,2);

近期文章

  • 在Android中组合来自服务器的JSON表
  • 正则表达式。 在php中查找函数名称
  • PHP函数从数组中获取所需的值
  • 在数据库和另一台PC上输入更新
  • 通过php和bash执行服务命令
  • 在Lightbox / Modal中加载PHP成功消息
  • 更新选择内容而不重新加载表单
  • 用GD透明背景绘制文本
  • 在while循环中更改id后添加新元素
  • 可用CMS的细微特征
  • PHP使用$ _SERVER ['HTTP_REFERER']创建反向链接
  • Bootstrap Select2 - 无法通过AJAX填充
  • PDO mysql:如何知道插入是否成功
  • php验证期间文本字段为空白[关闭]
  • mysqli_num_rows返回false而不是true [关闭]
  • 警报用户触发更新到mysql表
  • 如何将Html输入值添加到PHP数组中?
  • Laravel中3个数据库表之间的关系
  • MySQL选择all并从特定id开始
  • 创建新页面后无法获取ACF字段

Copyright ©2022 我爱占星 All Rights Reserved.

浙ICP备2022030071号-1

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

友情链接:代码精华