0Pricing
Java Academy · Lesson

Math Rounding and Limits

floor, ceil, round, min, max.

Rounding and Limits

This lesson focuses on the rounding family of Math methods (floor, ceil, round) and on clamping values using min and max.

Math.floor

Math.floor rounds down to the nearest integer value, returning a double. Math.floor(2.9) is 2.0.

public class Main {
    public static void main(String[] args) {
        System.out.println(Math.floor(2.9));
        System.out.println(Math.floor(-2.1));
    }
}

All lessons in this course

  1. The Math Class
  2. Generating Random Numbers
  3. Random Ranges and Shuffling
  4. Math Rounding and Limits
← Back to Java Academy