Home >Backend Development >PHP Problem >How to add one and round up if the integers are not divisible in php

How to add one and round up if the integers are not divisible in php

WBOY
WBOYOriginal
2022-05-07 10:57:201977browse

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)".

How to add one and round up if the integers are not divisible in php

The operating environment of this article: Windows 10 system, PHP version 7.1, Dell G3 computer

How to add one if php is not divisible

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:

How to add one and round up if the integers are not divisible in php

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!

Statement:
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