How to use php division function

藏色散人
Release: 2023-03-06 19:30:01
Original
4264 people have browsed it

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

2,

function Detailed explanation

float ceil ( float value )
Copy after login

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

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

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

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

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!

Related labels:
php
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!