Home  >  Article  >  Backend Development  >  How to implement rounding and division in php

How to implement rounding and division in php

藏色散人
藏色散人Original
2021-09-22 11:30:363493browse

In PHP, you can use the ceil() function to achieve rounding and division. The function of this function is to round up to the nearest integer. Its usage syntax is "ceil(x)", and the parameter x represents a need A number that is rounded up.

How to implement rounding and division in php

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

How to achieve integer division up in php?

ceil() function rounds up to the nearest integer.

Syntax

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

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));
?>

Output:

1
1
5
6
-5
-5

Recommended learning:《 PHP video tutorial

The above is the detailed content of How to implement rounding and division 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