最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
round() 函数对浮点数进行四舍五入
时间:2022-06-24 20:11:23 编辑:袖梨 来源:一聚教程网
语法
round(x,prec)参数 描述
x 可选。规定要舍入的数字。
prec 可选。规定小数点后的位数。
说明
返回将 x 根据指定精度 prec (十进制小数点后数字的数目)进行四舍五入的结果。prec 也可以是负数或零(默认值)。
提示和注释
注释:php教程 默认不能正确处理类似 "12,300.2" 的字符串。
注释:prec 参数是在 php 4 中被引入的。。
*/
echo round(3.4); //输出3
echo "
";
echo round(3.5); //输出4
echo "
";
echo round(3.6); //输出4
echo "
";
echo round(3.6,0); //输出4
echo "
";
echo round(1.95583,2); //输出1.96
echo "
";
echo round(1241757,-3); //输出1242000
echo "
";
echo round(4.045,2); //输出4.05
echo "
";
echo round(4.055,2); //输出4.06
//使用stdround函数代替php的round函数
?>
function stdround($num, $d=0)
{
return round($num + 0.0001 / pow(10, $d), $d);
}
echo "round(1.005,2)= ".round(1.005,2). "n ";
echo "round(1.015,2)= ".round(1.015,2). "n ";
echo "round(1.025,2)= ".round(1.025,2). "n ";
echo "round(1.035,2)= ".round(1.035,2). "n ";
echo "round(1.045,2)= ".round(1.045,2). "n ";
echo "round(1.055,2)= ".round(1.055,2). "n ";
echo "round(1.065,2)= ".round(1.065,2). "n ";
echo "round(1.075,2)= ".round(1.075,2). "n ";
echo "round(1.085,2)= ".round(1.085,2). "n ";
echo "round(1.095,2)= ".round(1.095,2). "n ";
echo "stdround(1.005,2)= ".stdround(1.005,2). "n ";
echo "stdround(1.015,2)= ".stdround(1.015,2). "n ";
echo "stdround(1.025,2)= ".stdround(1.025,2). "n ";
echo "stdround(1.035,2)= ".stdround(1.035,2). "n ";
echo "stdround(1.045,2)= ".stdround(1.045,2). "n ";
echo "stdround(1.055,2)= ".stdround(1.055,2). "n ";
echo "stdround(1.065,2)= ".stdround(1.065,2). "n ";
echo "stdround(1.075,2)= ".stdround(1.075,2). "n ";
echo "stdround(1.085,2)= ".stdround(1.085,2). "n ";
echo "stdround(1.095,2)= ".stdround(1.095,2). "n ";
$m=0.000000000000001;
echo "n ";
echo "round(1.005+{$m},2)= ".round(1.005+$m,2). "n ";
echo "round(1.015+{$m},2)= ".round(1.015+$m,2). "n ";
echo "round(1.025+{$m},2)= ".round(1.025+$m,2). "n ";
echo "round(1.035+{$m},2)= ".round(1.035+$m,2). "n ";
echo "round(1.045+{$m},2)= ".round(1.045+$m,2). "n ";
echo "round(1.055+{$m},2)= ".round(1.055+$m,2). "n ";
echo "round(1.065+{$m},2)= ".round(1.065+$m,2). "n ";
echo "round(1.075+{$m},2)= ".round(1.075+$m,2). "n ";
echo "round(1.085+{$m},2)= ".round(1.085+$m,2). "n ";
echo "round(1.095+{$m},2)= ".round(1.095+$m,2). "n ";
echo "round(1.005,2)= ".round(1.005,2). "n ";
echo "round(1.015,2)= ".round(1.015,2). "n ";
echo "round(1.025,2)= ".round(1.025,2). "n ";
echo "round(1.035,2)= ".round(1.035,2). "n ";
echo "round(1.045,2)= ".round(1.045,2). "n ";
echo "round(1.055,2)= ".round(1.055,2). "n ";
echo "round(1.065,2)= ".round(1.065,2). "n ";
echo "round(1.075,2)= ".round(1.075,2). "n ";
echo "round(1.085,2)= ".round(1.085,2). "n ";
echo "round(1.095,2)= ".round(1.095,2). "n ";
相关文章
- 王者荣耀S38新赛季前瞻有什么更新 S38版本前瞻直播优化内容介绍 11-27
- 王者荣耀心愿系统升级怎么玩 王者荣耀心愿系统升级活动介绍 11-27
- 《原神》茜特菈莉命座效果介绍 11-27
- 《原神》暝视寻灵织卷活动玩法介绍 11-27
- 《原神》火神玛薇卡突破材料汇总 11-27
- 《原神》茜特菈莉突破材料汇总 11-27