Facebook Page Twitter Page LinkedIn Page
× PHP Tutorial PHP Advanced PHP Resources


The PHP Math round() function returns the value of argument rounded to its nearest integer. The function can be overloaded and it can take float and double arguments. In special cases it returns the following:

  • If the argument is NaN, the result is 0.
  • If the argument is negative infinity or any value less than or equal to the value of Integer.MIN_VALUE or Long.MIN_VALUE, the result is equal to the value of Integer.MIN_VALUE or Long.MIN_VALUE.
  • If the argument is positive infinity or any value greater than or equal to the value of Integer.MAX_VALUE or Long.MAX_VALUE, the result is equal to the value of Integer.MAX_VALUE or Long.MAX_VALUE.

Syntax

round(number)

Parameters

number Required. Specify a floating point value to be rounded.

Return Value

Returns the value of argument rounded to its nearest integer.

Example:

In the example below, round() function returns the value of argument rounded to its nearest integer.

public class MyClass {
 public static void main(String[] args) {
  System.out.println(Math.round(48.45));   
  System.out.println(Math.round(48.55));   
 }
}

The output of the above code will be:

48
49

❮ PHP Math Functions

5