Home > Backend Development > PHP Tutorial > Detailed explanation of PHP rounding function code

Detailed explanation of PHP rounding function code

藏色散人
Release: 2023-04-05 19:40:01
Original
3730 people have browsed it

This article mainly introduces how to use PHP rounding-related functions, namely intval() function, round() function, ceil() function, floor() function. I hope it will be helpful to friends who need it. Helps!

Detailed explanation of PHP rounding function code

1. intval() function

Code example:

<?php
$num = 3.1415926;
$num2 = 3.6;
 
echo intval($num).&#39;<br>&#39;;
echo  intval($num2);
echo "<hr>";
Copy after login

Output:

3
3
Copy after login
Copy after login

2. round() function

Code example:

<?php
$num = 3.1415926;
$num2 = 3.6;
 
echo round($num).&#39;<br>&#39;;
echo  round($num2);
echo "<hr>";
Copy after login

Output:

3
4
Copy after login

3. ceil() function

<?php
$num = 3.1415926;
$num2 = 3.6;
 
echo ceil($num).&#39;<br>&#39;;
echo  ceil($num2);
echo "<hr>";
Copy after login

Output:

4
4
Copy after login

4. Floor() function

<?php
$num = 3.1415926;
$num2 = 3.6;
 
echo floor($num).&#39;<br>&#39;;
echo  floor($num2);
Copy after login

Output:

3
3
Copy after login
Copy after login

Summary of PHP rounding function:

intval() function means to obtain the integer value of a variable.

The round() function represents rounding of floating point numbers.

The ceil() function represents further rounding.

The floor() function represents rounding by rounding.

Related recommendations: "PHP Tutorial"

The above is the detailed content of Detailed explanation of PHP rounding function code. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
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