Dart int floor()
Syntax & Examples

int.floor() method

The `floor` method in Dart returns this integer itself.


Syntax of int.floor()

The syntax of int.floor() method is:

 int floor() 

This floor() method of int returns this.

Return Type

int.floor() returns value of type int.



✐ Examples

1 Floor of a positive integer

In this example,

  1. We assign the value 5 to the integer variable num1.
  2. We obtain the floor of num1 using the floor() method, which is the number itself.
  3. We print the result to standard output.

Dart Program

void main() {
  int num1 = 5;
  int floorNum1 = num1.floor();
  print('Floor of $num1: $floorNum1');
}

Output

Floor of 5: 5

2 Floor of a negative integer

In this example,

  1. We assign the value -3 to the integer variable num2.
  2. We obtain the floor of num2 using the floor() method, which is the number itself.
  3. We print the result to standard output.

Dart Program

void main() {
  int num2 = -3;
  int floorNum2 = num2.floor();
  print('Floor of $num2: $floorNum2');
}

Output

Floor of -3: -3

3 Floor of a positive integer

In this example,

  1. We assign the value 10 to the integer variable num3.
  2. We obtain the floor of num3 using the floor() method, which is the number itself.
  3. We print the result to standard output.

Dart Program

void main() {
  int num3 = 10;
  int floorNum3 = num3.floor();
  print('Floor of $num3: $floorNum3');
}

Output

Floor of 10: 10

Summary

In this Dart tutorial, we learned about floor() method of int: the syntax and few working examples with output and detailed explanation for each example.