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.


About the author



rahimv has over 15 years of experience in designing and developing Java applications. His areas of expertise are J2EE and eCommerce. If you like the website, follow him on Facebook, Twitter or Google Plus.

Add Comment

Your email address will not be published. Required fields are marked *