Simple example of rounding in php

小云云
Release: 2023-03-21 13:32:01
Original
1229 people have browsed it

This article mainly shares with you a simple example of rounding in PHP. There are many methods for number processing in PHP. The following are commonly used:

number_format — separated by thousands Format a number
money_format — Format a number into a currency string
round — Round floating point numbers
ceil() - rounding to the nearest integer
floor() - Rounding by rounding
mt_rand() - random number
mt_getrandmax — Displays the maximum possible value of a random number, returning the largest random number that can be returned by calling mt_rand(). 32-bit PHP can only return a maximum of 2147483647

Today I will talk about the round function. The correct way to use it is as follows! If we put that 100 outside, the result will not be what we want. If you encounter this problem in an actual project, record it.

round(($a/$b) * 100, 1)
Copy after login

Related recommendations:

JS processing data rounding (detailed explanation of the difference between tofixed and round)

JS processing data rounding Detailed explanation

3 ways to implement rounding in PHP

The above is the detailed content of Simple example of rounding in php. 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