Java Basic Examples

Round float or double to integer using Java Math class

This Java example shows how to round float or double number to integer using round() method of Java Math class.

How to round float or double to integer?

Use round() static method of Java Math class to round float or double number.


This method returns closest integer number to the argument.


Noteround(float f) returns int while round(double d) returns long value.

Internally, 0.5 is added to the argument number and floor value is taken. Result is then casted to integer value as given below.


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

Want to learn quickly?
Try one of the many quizzes. I promise you will not be disappointed.