.round()
The Math.round()
method returns an int
or long
value that is closest to the number provided.
Syntax
Math.round(n)
The .round()
method takes one parameter n
, the value that is to be rounded.
Example
The following example demonstrates using .round()
to round the value 1.8 to the nearest integer:
public class Test {public static void main(String args[]) {int n = Math.round(1.8);int m = Math.round(5.2);System.out.println(n);System.out.println(m);}}
This will produce the following output:
25
Looking to contribute?
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.