The `ceil` method in Dart returns the integer itself because integers are already whole numbers and cannot have a ceiling.
The syntax of int.ceil() method is:
int ceil()
This ceil() method of int returns this.
int.ceil() returns value of type int
.
In this example,
num
with the value 4.ceil()
method on num
returns the integer itself.void main() {
int num = 4;
int ceilNum = num.ceil();
print('Ceil of $num: $ceilNum');
}
Ceil of 4: 4
In this example,
negativeNum
with the value -3.ceil()
method on negativeNum
returns the integer itself.void main() {
int negativeNum = -3;
int ceilNegative = negativeNum.ceil();
print('Ceil of $negativeNum: $ceilNegative');
}
Ceil of -3: -3
In this example,
integerNum
with the value 7.ceil()
method on integerNum
returns the integer itself.void main() {
int integerNum = 7;
int ceilInteger = integerNum.ceil();
print('Ceil of $integerNum: $ceilInteger');
}
Ceil of 7: 7
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.