Home >Backend Development >PHP Problem >How to add one and round up if the integers are not divisible in php
In PHP, you can use the ceil() function to round the result by one when it is not divisible. This function is used to round up to the nearest integer, that is, it can return a value that is not less than the specified value. The smallest integer. If the specified value has a decimal part, it will be rounded up by one. If there is no decimal part, the original value will be returned directly. The syntax is "ceil (dividend/divisor)".
The operating environment of this article: Windows 10 system, PHP version 7.1, Dell G3 computer
Round up, and add 1 if there is a decimal: ceil()
Returns the next integer that is not less than value. If value has a decimal part, it will be rounded up by one.
This method is often used when we write paging classes to calculate the number of pages.
ceil(3.14159); // 4 ceil(3.64159); // 4
ceil() function rounds up to the nearest integer. The nearest integer value rounded up.
Grammar
ceil(number);
The example is as follows:
<?php echo(ceil(10/3)); ?>
Output result:
Recommended learning:《PHP video tutorial》
The above is the detailed content of How to add one and round up if the integers are not divisible in php. For more information, please follow other related articles on the PHP Chinese website!