This article will use PHP to round up the numbers to keep n decimal digits, as well as using PHP for the number of rounding method to do a small sum.
(1) PHP retains three decimal places and rounded
$num =0.0215489;
Echo sprintf ("%.3f", $num); 0.022
(2) PHP keep three decimal digits not rounded
$num =0.0215489;
Echo substr (sprintf ("%.4f", $num), 0,-1); 0.021
(3) php into a method to take an integer (this in the paging program in the number of pages in the program will be used)
echo ceil (4.3); 5
Echo ceil (9.999); 10
(4) The method of the PHP house to take the integer
echo floor (4.3); 4
Echo Floor (9.999);//9
Articles that you may be interested in
- PHP statistics online numbers, accurate statistics online number of ways
- Summary of methods for using Curl post submission data and get access to Web page data in PHP
- PHP's most accurate string length intercept function
- PHP compressed HTML page code to reduce network data transfer, clear spaces, tabs, comment marks
- Introduction to the parallel set, intersection and difference set functions of arrays in PHP
- Powerful PHP Image processing class (watermark, transparency, zoom, sharpen, rotate, flip, cut, invert color)
- PHP presses the element to the array header (Array_unshift usage)
- PHP uses Array_flip to implement array key exchange to remove duplicate value of array