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,
- We create an integer variable
numwith the value 4. - Since integers are whole numbers, calling the
ceil()method onnumreturns the integer itself. - 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,
- We create an integer variable
negativeNumwith the value -3. - Since integers are whole numbers, calling the
ceil()method onnegativeNumreturns the integer itself. - 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,
- We create an integer variable
integerNumwith the value 7. - Since integers are whole numbers, calling the
ceil()method onintegerNumreturns the integer itself. - 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.