Dart int ceil()
Syntax & Examples

int.ceil() method

The `ceil` method in Dart returns the integer itself because integers are already whole numbers and cannot have a ceiling.


Syntax of int.ceil()

The syntax of int.ceil() method is:

 int ceil() 

This ceil() method of int returns this.

Return Type

int.ceil() returns value of type int.



✐ Examples

1 Ceil of an integer

In this example,

  1. We create an integer variable num with the value 4.
  2. Since integers are whole numbers, calling the ceil() method on num returns the integer itself.
  3. We then print the result to standard output.

Dart Program

void main() {
  int num = 4;
  int ceilNum = num.ceil();
  print('Ceil of $num: $ceilNum');
}

Output

Ceil of 4: 4

2 Ceil of a negative integer

In this example,

  1. We create an integer variable negativeNum with the value -3.
  2. Since integers are whole numbers, calling the ceil() method on negativeNum returns the integer itself.
  3. We then print the result to standard output.

Dart Program

void main() {
  int negativeNum = -3;
  int ceilNegative = negativeNum.ceil();
  print('Ceil of $negativeNum: $ceilNegative');
}

Output

Ceil of -3: -3

3 Ceil of an integer

In this example,

  1. We create an integer variable integerNum with the value 7.
  2. Since integers are whole numbers, calling the ceil() method on integerNum returns the integer itself.
  3. We then print the result to standard output.

Dart Program

void main() {
  int integerNum = 7;
  int ceilInteger = integerNum.ceil();
  print('Ceil of $integerNum: $ceilInteger');
}

Output

Ceil of 7: 7

Summary

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