Dart num ceil()
Syntax & Examples


num.ceil() method

The `ceil` method in Dart returns the least integer that is not less than the given number.


Syntax of num.ceil()

The syntax of num.ceil() method is:

 int ceil() 

This ceil() method of num returns the least integer no smaller than this.

Return Type

num.ceil() returns value of type int.



✐ Examples

1 Ceil of a decimal number

In this example,

  1. We create a num variable num with the value 4.2.
  2. We use the ceil() method to get its ceiling value.
  3. We then print the result to standard output.

Dart Program

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

Output

Ceil of 4.2: 5

2 Ceil of a negative decimal number

In this example,

  1. We create a num variable negativeNum with the value -3.8.
  2. We use the ceil() method to get its ceiling value.
  3. We then print the result to standard output.

Dart Program

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

Output

Ceil of -3.8: -3

3 Ceil of an integer

In this example,

  1. We create a num variable integerNum with the value 7.
  2. We use the ceil() method to get its ceiling value.
  3. We then print the result to standard output.

Dart Program

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

Output

Ceil of 7: 7

Summary

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