Java Basic Examples

Round down a number using floor method of Java Math class

This Java example shows how to round down a number using floor method of Java Math class.

How to round down a number using floor method of Math class?

Use floor() method of Java Math class to round down a number.

This method returns largest double number which is equal to or less than the argument and is equal to an integer.

Output

Please note that -5.01 and -5.99 return -6 because -6 is the smallest integer less than both of them.

Please also not that floor() method returns double. You may need to cast it to appropriate data type from double value.

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.

Tags