Java Mathrint() Method
Example
Round numbers to the nearest integer:
System.out.println(Math.rint(0.5));System.out.println(Math.rint(1.5));System.out.println(Math.rint(5));System.out.println(Math.rint(5.1));System.out.println(Math.rint(-5.1));System.out.println(Math.rint(-5.9));Definition and Usage
Therint() method rounds a number to the nearest integer. If there are two integers that are equally close to the number then the even integer will be returned.
Note: This method is very similar toround(). The main differences betweenrint() andround() are:
round()returnslongorintdata types whilerint()returns adouble.- When the decimal part of the number is exactly 0.5,
rint()returns the nearest even integer whileround()returns the highest of the two nearest integers
Syntax
public static double rint(doublenumber)Parameter Values
| Parameter | Description |
|---|---|
| number | Required. A number to round. |
Technical Details
| Returns: | Adouble value representing the nearest integer to a number. |
|---|---|
| Java version: | Any |
❮ Math Methods

