Jump to: navigation, search

Php round

From w3cyberlearnings

Contents

PHP function x1

This function rounds a float number specifies by the precision.

Syntax x1

  • Val: a number
  • precision: dicimal digit to round to
  • mode:PHP_ROUND_HALF_UP, PHP_ROUND_HALF_DOWN, PHP_ROUND_HALF_EVEN, or PHP_ROUND_HALF_ODD.
x1(Val, precision, mode);

Example 1

<?php
echo round(3.4);
echo"<br/>";
echo round(3.6);
?>

Output

3
4

Example 2

<?php
echo round(10.5, 0, PHP_ROUND_HALF_UP);   // 11
echo "<br/>";
echo round(10.5, 0, PHP_ROUND_HALF_DOWN); // 10
echo "<br/>";
echo round(10.5, 0, PHP_ROUND_HALF_EVEN); // 10
echo "<br/>";
echo round(10.5, 0, PHP_ROUND_HALF_ODD);  // 11
echo "<br/>";
?>

Example 3

<?php
echo round(9.5, 0, PHP_ROUND_HALF_UP);   // 10
echo "<br/>";
echo round(9.5, 0, PHP_ROUND_HALF_DOWN); // 9
echo "<br/>";
echo round(9.5, 0, PHP_ROUND_HALF_EVEN); // 10
echo "<br/>";
echo round(9.5, 0, PHP_ROUND_HALF_ODD);  // 9
echo "<br/>";
?>

Related Links


Navigation
Web
SQL
MISC
References