本文操作环境:windows10系统、PHP7.1版、Dell G3电脑。php怎么转换成6位小数1、利用round()函数。round() 函数对浮点数进行四舍五入。语法round(number,precision,mode);numbe
本文操作环境:windows10系统、PHP7.1版、Dell G3电脑。
1、利用round()函数。
round() 函数对浮点数进行四舍五入。
语法
round(number,precision,mode);
number 必需。规定要舍入的值。
precision 可选。规定小数点后的尾数。默认是 0,也可以为负数。
mode 可选。规定表示舍入模式的常量:
2、利用sprintf()函数。
sprintf() 函数把格式化的字符串写入一个变量中。
arg1、arg2、++ 参数将被插入到主字符串中的百分号(%)符号处。该函数是逐步执行的。在第一个 % 符号处,插入 arg1,在第二个 % 符号处,插入 arg2,依此类推。
语法
sprintf(fORMat,arg1,arg2,arg++)
format 必需。规定字符串以及如何格式化其中的变量。
3、利用number_format()函数。
number_format() 函数通过千位分组来格式化数字。
该函数支持一个、两个或四个参数(不是三个)。
语法
number_format(number,decimals,decimalpoint,separator)
示例如下
<?php
$num = 10.456715616;
//第一种:利用round()对浮点数进行四舍五入
echo round($num,6)."<br>";
//第二种:利用sprintf格式化字符串
$format_num = sprintf("%.6f",$num);
echo $format_num."<br>";
//第三种:利用千位分组来格式化数字的函数number_format()
echo number_format($num, 6);
?>
输出结果:
--结束END--
本文标题: php怎么转换成6位小数
本文链接: https://www.lsjlt.com/news/1510.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0