Open In App
Related Articles

Java Math round() method with Example

Improve Article
Save Article
Like Article

The java.lang.Math.round() is a built-in math function which returns the closest long to the argument. The result is rounded to an integer by adding 1/2, taking the floor of the result after adding 1/2, and casting the result to type long.

  • 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, the result is equal to the value of Integer.MIN_VALUE.
  • If the argument is positive infinity or any value greater than or equal to the value of Integer.MAX_VALUE, the result is equal to the value of Integer.MAX_VALUE.


public static int round(float val)
val - floating-point value to be rounded to an integer. 

The method returns the value of the argument rounded to the nearest int value.

Example: To show working of java.lang.Math.round() function

// Java program to demonstrate working
// of java.lang.Math.round() method
import java.lang.Math;
class Gfg {
    // driver code
    public static void main(String args[])
        // float numbers
      float x = 4567.9874f;
      // find the closest int for these floats
      float y = -3421.134f;
      // find the closest int for these floats
      double positiveInfinity = Double.POSITIVE_INFINITY;
      // returns the Integer.MAX_VALUE value when 


Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Last Updated : 11 Apr, 2018
Like Article
Save Article
Similar Reads
Complete Tutorials