Home >Backend Development >PHP Problem >What is the rounding function in php
In PHP, the rounding function is the round() function, which can round floating point numbers; the syntax format is "round(number)", and the parameter number specifies the value to be rounded and cannot be omitted .
The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer
In PHP, the rounding function is round ()function.
Let’s take a look at an example:
<?php echo(round(0.60) . "<br>"); echo(round(0.50) . "<br>"); echo(round(0.49) . "<br>"); echo(round(-4.40) . "<br>"); echo(round(-4.60)); ?>
Output:
1 1 0 -4 -5
Explanation:
round(number,precision,mode);
Description | |
---|---|
number | Required. Specifies the value to be rounded.|
precision | Optional. Specifies the number of digits after the decimal point. Default is 0, can also be negative.|
mode | Optional. Specifies a constant representing the rounding mode:
|
<?php echo(round(0.5) . "<br>"); echo(round(0.495,1) . "<br>"); echo(round(0.495,2,PHP_ROUND_HALF_DOWN) . "<br>"); echo(round(-4.405,2) . "<br>"); ?>Output:
1 0.5 0.49 -4.41Recommended learning: "
PHP Video tutorial》
The above is the detailed content of What is the rounding function in php. For more information, please follow other related articles on the PHP Chinese website!