Practical application of php round function (with examples)

烟雨青岚
Release: 2023-04-08 19:40:01
forward
2666 people have browsed it

Practical application of php round function (with examples)

Practical application of php round function (with examples)

php round function definition and usage

php The round function is used to round floating point numbers. Its syntax is round(x,prec). The parameter x is optional and refers to the number to be rounded; prec is optional and refers to the decimal point. The number of digits after.

Syntax

round(x,prec)
Copy after login

Parameter x is optional. Specifies the number to be rounded. Parameter prec is optional. Specifies the number of digits after the decimal point.

Description

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

Tips and Notes

*Note: PHP cannot handle strings like "12,300.2" correctly by default.

*Note: The prec parameter was introduced in PHP 4. .

Example:

<?php
echo(round(0.60));
echo(round(0.50));
echo(round(0.49));
echo(round(-4.40));
echo(round(-4.60));
?>
Copy after login

Output:

1
1
0
-4
-5
Copy after login

The above is the details of how to use the php round function, I hope everyone will benefit from watching it.

————————————————

Copyright statement: This article is an original article by CSDN blogger "Herborist" and follows CC 4.0 BY-SA Copyright agreement, please attach the original source link and this statement when reprinting.

Original link: https://blog.csdn.net/weixin_44007570/article/details/90770878

Recommended tutorial: "PHP Tutorial"

The above is the detailed content of Practical application of php round function (with examples). For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:csdn.net
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