The java.util Math round method is used to round a given number to the nearest integer value. It takes one argument, a double value, and returns an integer value.
Examples: 1. Round a double value to the nearest integer:
double num = 3.75; int roundedNum = Math.round(num); System.out.println(roundedNum); // Output: 4
2. Round a double value to the nearest tenth:
double num = 3.758; int roundedNum = Math.round(num * 10) / 10; System.out.println(roundedNum); // Output: 3.8
This method belongs to the java.util package library.
Java Math.round - 30 examples found. These are the top rated real world Java examples of java.util.Math.round extracted from open source projects. You can rate examples to help us improve the quality of examples.