Home >Backend Development >PHP Problem >How to use php division function

How to use php division function

藏色散人
藏色散人Original
2020-10-23 09:30:494323browse

How to use the php division function: First create a PHP sample file; then calculate the division result through "floatval($resf/$rese);" and other methods.

How to use php division function

Recommended: "PHP Video Tutorial"

php Division

1. Floating point division: $resu=floatval($resf/$rese); The function to remove the number of decimal places is round($name,number);

for example: $resultke=round($resu, 2);

2,

function Detailed explanation

float ceil ( float value )

Returns the next integer that is not less than value. If value 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:

<?php
echo ceil(4.333); // 5
?>

2. floor — rounding function

Detailed explanation of function

float floor (float value)

Returns the next integer not greater than value, rounding off the decimal part of value. The type returned by floor() is still float because the range of float values ​​is usually larger than that of integer.

Example:

<?php
echo floor(9.999); // 9
?>

3. round - rounding function

Detailed explanation of function

float round (float val [, int precision])

Returns the result of rounding val according to the specified precision (the number of decimal digits after the decimal point). precision can also be negative or zero (default).

Example 1. round() example

<?php
echo round(3.4); // 3
echo round(3.5); // 4
echo round(3.6, 0); // 4
echo round(1.95583, 2); // 1.96
echo round(1241757, -3); // 1242000
?>

Because the data types returned by our rounding function are all float types, generally we can use the intval function to force the data type to an integer type.

Example:

intval—Force data into integer type

Example intval()

<?php
echo intval(4.3); //4
echo intval(4.6); // 4
?>

The above is the detailed content of How to use php division function. 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