What is the floor() function in Dart?
Overview
The floor() function in Dart returns the next largest integer that is less than or equal to a specified number.
The figure below shows the mathematical representation of the floor() function.
Syntax
number.floor()
Parameter
This function does not require a parameter.
Return value
The floor() function returns the next largest integer less than or equal to the number.
Code example
The code below demonstrates the use of the floor() function in Dart.
import 'dart:convert';void main() {//positive numberprint("The value of (1.5).floor(): ${(1.5).floor()} ");// negative numberprint("The value of (-5.5).floor(): ${(-5.5).floor()} ");//zeroprint("The value of (0).floor(): ${(0).floor()}");}
Explanation
- Line 5: We calculate the floor value of the positive number
1.5usingfloor().
- Line 8: We calculate the floor value of the negative number
-5.5usingfloor(). - Line 11: We calculate the floor value
0usingfloor().