$num = 10.4567;

    //第一种:利用round()对浮点数进行四舍五入
echo round($num,2); //10.46 //第二种:利用sprintf格式化字符串
$format_num = sprintf("%.2f",$num);
echo $format_num; //10.46 //第三种:利用千位分组来格式化数字的函数number_format()
echo number_format($num, 2); //10.46
//或者如下
echo number_format($num, 2, '.', ''); //10/46

PHP保留两位小数的几种方法的更多相关文章

  1. (后台)Java:对double值进行四舍五入,保留两位小数的几种方法

    mport java.text.DecimalFormat; DecimalFormat df = new DecimalFormat("######0.00"); double ...

  2. php保留两位小数的3种方法

    <?php $num = 8.16789; //第一种:利用round()对浮点数进行四舍五入 echo round($num,2).PHP_EOL; //8.17 //第二种:利用sprint ...

  3. Java:对double值进行四舍五入,保留两位小数的几种方法

    1. 功能 将程序中的double值精确到小数点后两位.可以四舍五入,也可以直接截断. 比如:输入12345.6789,输出可以是12345.68也可以是12345.67.至于是否需要四舍五入,可以通 ...

  4. Python中保留两位小数的几种方法

    https://blog.csdn.net/Jerry_1126/article/details/85009810 保留两位小数,并做四舍五入处理方法一: 使用字符串格式化>>> a ...

  5. Double值保留两位小数的四种方法

    public class DoubleTest { //保留两位小数第三位如果大于4会进一位(四舍五入) double f = 6.23556; /** *使用精确小数BigDecimal */ pu ...

  6. JS保留两位小数的几种方法

    四舍五入 以下处理结果会四舍五入: var num =2.446242342; num = num.toFixed(2); // 输出结果为 2.45 不四舍五入 以下处理结果不会四舍五入: 第一种, ...

  7. php 基础 PHP保留两位小数的几种方法

    $num = 10.4567; //第一种:利用round()对浮点数进行四舍五入 echo round($num,2); //10.46 //第二种:利用sprintf格式化字符串 $format_ ...

  8. JAVA 保留两位小数的四种方法

    import java.math.BigDecimal; import java.text.DecimalFormat; import java.text.NumberFormat; publiccl ...

  9. php取两位小数的几种方法

    php取两位小数的几种方法 一.总结 一句话总结: 1.round   四舍五入 2.sprintf   c语言方式 3.number_format 千分位数字格式化的那个函数 二.php取两位小数的 ...

随机推荐

  1. Android BLE 蓝牙低功耗教程,中央BluetoothGatt和周边BluetoothGattServer的实现

    http://blog.csdn.net/wave_1102/article/details/39271693 分类: Android(105) 作者同类文章X Android4.3 规范了BLE的A ...

  2. Registration Code

    [sublime text 3] Michael BarnesSingle User LicenseEA7E-8213858A353C41 872A0D5C DF9B2950 AFF6F667C458 ...

  3. How to prevent SQL injection attacks?

    In our earlier tutorial on SQL Injection, one way to have prevented the SQL injection attack was by ...

  4. 使用NSURLSession

    NSURLConnection在iOS9被宣布弃用,NSURLSession从13年发展到现在,终于迎来了它独步江湖的时代.NSURLSession是苹果在iOS7后为HTTP数据传输提供的一系列接口 ...

  5. Linux用户配置sudo权限

    Linux用户配置sudo权限 创建sudo权限用户 #useradd supope #passwd supope #visudo #supope         ALL=(ALL)       AL ...

  6. php +html5 websocket 聊天室

    针对内容比较长出错,修改后的解码函数 和 加码函数 原文请看上一篇 http://yixun.yxsss.com/yw3104.html function uncode($str,$key){ $ma ...

  7. 读取input:file的路径并显示本地图片的方法

    <!doctype html> <html> <head> <meta content="text/html; charset=UTF-8" ...

  8. SQLServer 使用smb存放数据文件

    安装smb: 服务器管理器->角色->文件服务 1.配置smb共享时,更改NTFS权限,需要将SQLServer启动域帐户加入,读.写.完全控制等权限 2.实例启动用户需要使用域帐户 3. ...

  9. mysql常用命令(2)

    1.连接Mysql 格式: mysql -h主机地址 -u用户名 -p用户密码 1.连接到本机上的MYSQL.首先打开DOS窗口,然后进入目录mysql\bin,再键入命令mysql -u root ...

  10. servlet定义

    . 运行在服务器上的java类