<?php
// 使用 round() 函数进行四舍五入取整
$number = 4.5;
$rounded_number = round($number); // 结果为 5
echo "原始数字: $number, 四舍五入后: $rounded_number";
// 如果需要指定小数位数,可以传递第二个参数
$number_with_decimal = 4.5678;
$rounded_to_two_decimals = round($number_with_decimal, 2); // 结果为 4.57
echo "原始数字: $number_with_decimal, 四舍五入到两位小数后: $rounded_to_two_decimals";
?>
解释说明:
round()
函数用于对浮点数进行四舍五入。上一篇:php hyperf
下一篇:php 数组追加
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站