PHP/Math/round

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

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

   <source lang="html4strict">

<?

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

?>

 </source>
   
  


Provide the number of decimal places to round to:

   <source lang="html4strict">

<?

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

?>

 </source>
   
  


round a double

   <source lang="html4strict">

<? echo round(2.56); echo "
";

echo round(1.22); echo "
"; echo round(55.22); ?>

      </source>