There are three main functions for rounding the numbers in various ways. We must know the difference between all three.

1) round()
2) ceil()
3) floor()

Let get into each one by one.

1) round()

This function takes three arguments.

value (required)

This is the float number which we want to round.

precision (optional)

This is the optional parameter. This number define upto how much decimal it should perform round, default value is 0.

mode (optional)

This is optional parameter and introduced from PHP 5.3, This parameter inform function to behave when it found the number exactly in between two decimal number. By default it performs PHP_ROUND_HALF_UP.

Possible values are PHP_ROUND_HALF_UP, PHP_ROUND_HALF_DOWN, PHP_ROUND_HALF_EVEN, or PHP_ROUND_HALF_ODD.

Note : mode parameter was introduced from PHP 5.3, By default it performs PHP_ROUND_HALF_UP.

Usage:

<?php
  echo round(2.5); // 3
  echo round(2.1); //2
  echo round(2.6); // 3
  echo round(2.96254,2); // 2.97
 
  echo round(3.5, 0, PHP_ROUND_HALF_UP);   // 4
  echo round(3.5, 0, PHP_ROUND_HALF_DOWN); // 3
  echo round(3.5, 0, PHP_ROUND_HALF_EVEN); // 4
  echo round(3.5, 0, PHP_ROUND_HALF_ODD);  // 3
 
  echo round(4.5, 0, PHP_ROUND_HALF_UP);   // 5
  echo round(4.5, 0, PHP_ROUND_HALF_DOWN); // 4
  echo round(4.5, 0, PHP_ROUND_HALF_EVEN); // 4
  echo round(4.5, 0, PHP_ROUND_HALF_ODD);  // 5
?>

2) floor()

This functions will return the next lowest value by rounding down the passed value.

This function takes only one argument which is float value for which we needs floor value.

Usage:

<?php
  echo floor(2.3); // 2
  echo floor(2.9); //2
  echo floor(-2.6); //-3
?>

3) ceil()

This functions will return the next highest value by rounding up the passed value.

This function takes only one argument which is float value for which we needs ceil value.

Usage:

<?php
  echo ceil(2.3); // 3
  echo ceil(2.9); //3
  echo ceil(-2.6); //-2
?>