Home > Backend Development > PHP Problem > How to round down in php

How to round down in php

藏色散人
Release: 2023-03-03 19:10:01
Original
8153 people have browsed it

In PHP, you can round down to the nearest integer through the floor function. The function of the floor function is to round down to the nearest integer. Its syntax is "floor(x)" and the return value is not greater than " The next integer of "x", round off the decimal part of "x".

How to round down in php

Recommendation: "PHP Video Tutorial"

In PHP, you can use the floor function to achieve rounding down.

PHP floor() function definition and usage

floor() function rounds down to the nearest integer.

Syntax

floor(x)
Copy after login

Parameters

x Required. A number.

Description

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

Example

In this example, we will apply the floor() function to different numbers:

<?php
echo(floor(0.60));
echo(floor(0.40));
echo(floor(5));
echo(floor(5.1));
echo(floor(-5.1));
echo(floor(-5.9))
?>
Copy after login

Output:

0
0
5
5
-6
-6
Copy after login

The above is the detailed content of How to round down in php. 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