PHP/Math/round

Материал из Web эксперт
Перейти к: навигация, поиск

float round ( float num [, int precision] ) rounds parameter to the nearest integer to its current value

 
<?
    $number = round(11.1); // 11
    $number = round(11.9); // 12
    $number = round(11.5); // 12
    $number = round(11); // 11
?>



Provide the number of decimal places to round to:

 
<?
    $a = round(4.4999); // 4
    $b = round(4.123456, 3); // 4.123
    $c = round(4.12345, 4); // 4.1235
    $d = round(1000 / 160); // 6
?>



round a double

<?
echo round(2.56); 
echo "<BR>";
      
echo round(1.22);     
echo "<BR>";
echo round(55.22);    
?>