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

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2023-03-15 22:28:01
Original
2028 people have browsed it

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
Copy after login

ceil() function rounds up to the nearest integer. The nearest integer value rounded up.

Grammar

ceil(number);
Copy after login

The example is as follows:

<?php
echo(ceil(10/3));
?>
Copy after login

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!

Related labels:
php
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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template