| ||||||
|
How to round a float to a specific decimal point in PHP
Previously I have discussed how additions, subtractions, multiplications and divisions can be performed using bc functions with the results being produced to a specified decimal point. However, what if a calculation is performed using a mix of methods, and rounding up the result with bc functions would actually end up infringing on the result's accuracy? This would be one instance where the PHP function rand() comes in handy. By simply placing the end result between the brackets we will end up with a specifically rounded number: <?php echo round(45.20322355043343, 4); ?> The result: 45.2032
|