Home > Backend Development > PHP Problem > What function does php use to round up?

What function does php use to round up?

(*-*)浩
Release: 2023-02-24 07:46:01
Original
3554 people have browsed it

In PHP, generally speaking, if you need to round up, use the ceil() function.

What function does php use to round up?

Grammar

ceil(x)
Copy after login

Instructions(recommended learning:PHP Programming from Beginner to Master)

Returns the next integer that is not less than x. If x has a decimal part, it will be rounded up by one. The type returned by ceil() is still float because the range of float values ​​is usually larger than that of integer.

Example

In this example, we will apply the ceil() function to different values:

<?php
echo(ceil(0.60);
echo(ceil(0.40);
echo(ceil(5);
echo(ceil(5.1);
echo(ceil(-5.1);
echo(ceil(-5.9));
?>
Copy after login

Output:

1
1
5
6
-5
-5
Copy after login

The above is the detailed content of What function does php use to round up?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template