Last updated on February 23, 2023
In the Dart programming language, the floor() method returns the largest integer less than or equal to the number. It doesn’t take any parameters and attaches with value or variable through dot notation.
For example, if you apply the floor() method on a double value of 10.50 then it would convert into an integer and return 10. It is because 10 is the largest integer and less than 10.50.
Syntax
number.floor()
Parameters
It doesn’t take any parameters.
Example
In this example, we will learn to use the floor() method. Create a variable with the var keyword and store a double value to it.
var doubleValue = 10.50;
In the next step, access the floor() method through dot notation that converts the value into an integer.
// attach floor() method and assign to variable
var convertedValue = doubleValue.floor();
// print variable’s value
print(convertedValue);
// Output: 10
In the above code, the floor() method is attached to the doubleValue variable and it is assigned to a new variable. The new variable stores the converted value.