Rounding numbers with PHP
round()
The round() function rounds the number passed in to the specified number of decimal places. If the decimal places is a negative number then the numbers to the left of the decimal place are rounded. If the decimal places parameter is not passed in then it defaults to zero and will round as an integer. 5 is round up and < 5 is rounded down.
echo round(125.751, 2); // 125.75
echo round(125.751, 1); // 125.8
echo round(125.751); // 126
echo round(125.751, -1); // 130
echo round(125.751, -2); // 100
Read more…