Home  >  Article  >  Backend Development  >  How to round up data in PHP

How to round up data in PHP

藏色散人
藏色散人Original
2019-09-17 17:34:256910browse

How to round up data in PHP

How to round up PHP data?

PHP data rounding up can be implemented through the ceil() function. The ceil() function means rounding up to the nearest integer.

The syntax is:

ceil(x)

Parameters

x required. A number.

Explanation

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:

Round up, add 1 if there is a decimal: ceil()

Returns the next integer that is not less than value, value if If there is a decimal part, round it up to one digit.

This method is often used when we write paging classes to calculate the number of pages.

ceil(3.14159); // 4
ceil(3.64159); // 4

For more PHP related knowledge, please visit the PHP Chinese website PHP Tutorial!

The above is the detailed content of How to round up data 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