The `ceil` method in Dart returns the least integer that is not less than the given number.
The syntax of double.ceil() method is:
int ceil()
This ceil() method of double returns the least integer no smaller than this
.
double.ceil() returns value of type int
.
In this example,
num
with the value 4.2.ceil()
method to get its ceiling value as an integer.void main() {
double num = 4.2;
int ceilNum = num.ceil();
print('Ceil of $num: $ceilNum');
}
Ceil of 4.2: 5
In this example,
negativeNum
with the value -3.8.ceil()
method to get its ceiling value as an integer.void main() {
double negativeNum = -3.8;
int ceilNegative = negativeNum.ceil();
print('Ceil of $negativeNum: $ceilNegative');
}
Ceil of -3.8: -3
In this example,
integerNum
with the value 7.0, which is already an integer.ceil()
method to get its ceiling value as an integer.void main() {
double integerNum = 7.0;
int ceilInteger = integerNum.ceil();
print('Ceil of $integerNum: $ceilInteger');
}
Ceil of 7: 7
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.