Home  >  Article  >  Backend Development  >  How to round down in php

How to round down in php

藏色散人
藏色散人Original
2020-08-05 09:17:048004browse

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)

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))
?>

Output:

0
0
5
5
-6
-6

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!

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