Flash cards
Review the key moves
What is the main idea behind Java Math floor() Method?
Lesson checks
Practice each idea before moving on
Short Mimo-style checks built from this lesson's code, terms, and sequence.
Which statement best captures the main point of this lesson?
Complete the missing token from the example code.
___.out.println(Math.floor(0.60));Put the learning moves in the order that makes the concept easiest to apply.
❮ Math Methods
Example
System.out.println(Math.floor(0.60));
System.out.println(Math.floor(0.40));
System.out.println(Math.floor(5));
System.out.println(Math.floor(5.1));
System.out.println(Math.floor(-5.1));
System.out.println(Math.floor(-5.9));Definition and Usage
The floor() method rounds a number DOWN to the nearest integer.
Tip
To round a number UP to the nearest integer, look at the ceil() method.
Tip
To round a number to the nearest integer in either direction, look at the round() method.
Note
For positive numbers the floor() method just removes the decimal part, but for negative numbers the integer part of the number will be changed if the number has a decimal part. If you only want to remove the decimal part, you can type cast the number as an integer.
Syntax
public static double floor(double
number )Parameter Values
| Parameter | Description |
|---|---|
| number | Required. A number to round down. |
Technical Details
| Returns: | A double value representing the nearest integer less or equal to a number. |
|---|---|
| Java version: | Any |