Skip to content

Round float or double to integer number using Java Math class

Java Math round method example shows how to round float or double number to an integer using the round method of the Java Math class.

How to round a number (float or double to integer) using the round method?

We can use the round static method of the Java Math class to round a float or double number.

or

This method returns the closest integer number to the argument.

Output

Note: The round(float f)  method returns an int value while the round(double d)  method returns a long value.

Internally, 0.5 is added to the argument number and a floor value is taken. The result is then cast to an integer value as given below.

Output

Also, check out how to get the floor number and how to get the ceiling number examples.

This example is a part of the Java Math class tutorial with examples.

Please let me know your views in the comments section below.

About the author

Leave a Reply

Your email address will not be published.