YouTip LogoYouTip

Number Round

# Java round() Method [![Image 3: Java Number Class](#)Java Number Class](#) * * * The round() method returns the closest int or long value, rounding to the nearest integer. **round** stands for "**rounding**", and the algorithm is **Math.floor(x+0.5)**, which means adding 0.5 to the original number and then taking the floor. Therefore, **Math.round(11.5)** results in 12, and Math.round(-11.5) results in -11. ### Syntax The method has the following syntax formats: long round(double d)int round(float f) ### Parameters * **d** -- a primitive data type of double or float * **f** -- a primitive data type of float ### Return Value Returns the closest int or long value, with the method specifying the return data type. ### Example ## Example public class Test{public static void main(String args[]){double d = 100.675; double e = 100.500; float f = 100; float g = 90 f; System.out.println(Math.round(d)); System.out.println(Math.round(e)); System.out.println(Math.round(f)); System.out.println(Math.round(g)); }} Compile the program above, and the output result is: 10110110090 * * Java Number Class](#)
← Number MaxNumber Floor β†’