Home > Article > Backend Development > Rounding in php_PHP tutorial
For example, I have 0.10456, do I want it to become 10.5%?
round
(PHP 3, PHP 4)
round -- Round floating point numbers
Explanation
float round (float val [, int precision])
Returns val according to Specifies the precision (number of decimal digits after the decimal point) for rounding results. precision can also be negative or zero (default).
Note
PHP cannot handle strings like "12,300.2" correctly by default. See Convert String to Numeric.
echo round(3.4); // 3
echo round(3.5); // 4
echo round(3.6); // 4
echo round(3.6, 0); // 4
echo round(1.95583, 2); // 1.96
echo round(1241757, -3); // 1242000
Note: The precision parameter is only available in PHP 4.
echo round(0.10456*100,1);
$num = 0.10456;
echo round(($num*100),1)."%";
?>