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