I would like to round my decimal number.
As I search on tutorial, We can use round
function.
Example I have this number 7.1
, when I tried to round it using
echo round("7.1");
It will show us: 7
But now I want if 7.1
it should be 8
. Is it possible to do it?
我建议使用ceil
函数,该函数会将数字四舍五入到最接近的值。
echo ceil('7.1');
There is 3 rounding functions: ceil
, floor
, round
.
Ceil will round numbers up. documentation
Floor will round numbers down. documentation
Round will round following basic rounding rules. 0.5 and higher rounds up. 0.4 and lower rounds down. documentation
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.