Round numbers to their nearest integers.
System.out.println(Math.rint(0.5)); |
The rint()
method in Java rounds a number to the nearest integer. In cases where there are two integers equally close to the number, the even integer is returned.
Note: This method is similar to round()
, with key differences:
round()
returns long or int data types, while rint()
returns a double.rint()
returns the nearest even integer, whereas round()
returns the higher of the two nearest integers.
public
|
Parameter |
Description |
number |
Please provide a number to be rounded. |
Returns: |
A double value representing the integer nearest to a given number. |
Java version: |
Any |