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

在PHP中删除不必要的小数位数

How can I cut unnecessary zeros at the end of a floating point value in PHP, like the following for example:

3.0 --> 3
12.56300 --> 12.563
etc.

You can just use (double) or (float) without (string)

echo (float)$input;

One easy way I found to do so is the following:

$output = (double) (string) $input;
number_format($number, number of digits);

for example

echo number_format(2.222222, 2); //2.22

近期文章

  • PHP xpath查询没有结果
  • Foreach里面的where语句?
  • 正则表达式搜索特殊标记
  • 在PHP或mySQL中减去两个字符串来计算差异[重复]
  • MYSQL提供的参数不是有效的MySQL-Link资源[重复]
  • preg_match仅适用于字符串
  • 如何使用while循环和在php中的变量中存储的fetch值从数据库中获取所有行数据
  • 为什么尽可能在代码中将PHP与HTML分开?
  • if / elseif / else问题[关闭]
  • php和sql随机值
  • 如何在PHP中运行MySQL查询并将数据发送回浏览器? [关闭]
  • php geo ip loc不起作用
  • 使用Bootstrap中心内容
  • 带有@符号的PHP stdobject用于密钥[复制]
  • 使用php获取正常的用户可读日期/时间
  • 如何重定向到控制器模板中的另一个操作?
  • Yii CGridView:selectionChanged未定义
  • time()和Date.now()之间有什么区别
  • 删除名称的一部分| PHP
  • Mac OS X上缺少PhpStorm部署菜单

Copyright ©2022 我爱占星 All Rights Reserved.

浙ICP备2022030071号-1

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

友情链接:代码精华