Dart double ceil()
Syntax & Examples

double.ceil() method

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


Syntax of double.ceil()

The syntax of double.ceil() method is:

 int ceil() 

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

Return Type

double.ceil() returns value of type int.



✐ Examples

1 Ceil of a decimal number

In this example,

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

Dart Program

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

Output

Ceil of 4.2: 5

2 Ceil of a negative decimal number

In this example,

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

Dart Program

void main() {
  double negativeNum = -3.8;
  int 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 double variable integerNum with the value 7.0, which is already an integer.
  2. We use the ceil() method to get its ceiling value as an integer.
  3. We then print the result to standard output.

Dart Program

void main() {
  double integerNum = 7.0;
  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 double: the syntax and few working examples with output and detailed explanation for each example.