Dart num ceilToDouble()
Syntax & Examples
num.ceilToDouble() method
The `ceilToDouble` method in Dart returns the least double integer value no smaller than the given number.
Syntax of num.ceilToDouble()
The syntax of num.ceilToDouble() method is:
double ceilToDouble()
This ceilToDouble() method of num returns the least double integer value no smaller than this.
Return Type
num.ceilToDouble() returns value of type double
.
✐ Examples
1 Ceil to double of a decimal number
In this example,
- We create a num variable
num1
with the value 4.2. - We use the
ceilToDouble()
method to get its ceiling value as a double. - We then print the result to standard output.
Dart Program
void main() {
num num1 = 4.2;
double ceilValue = num1.ceilToDouble();
print('Ceil to double of $num1: $ceilValue');
}
Output
Ceil to double of 4.2: 5
2 Ceil to double of a negative decimal number
In this example,
- We create a num variable
negativeNum
with the value -3.8. - We use the
ceilToDouble()
method to get its ceiling value as a double. - We then print the result to standard output.
Dart Program
void main() {
num negativeNum = -3.8;
double ceilValue = negativeNum.ceilToDouble();
print('Ceil to double of $negativeNum: $ceilValue');
}
Output
Ceil to double of -3.8: -3
3 Ceil to double of an integer
In this example,
- We create a num variable
integerNum
with the value 7.0, which is already an integer. - We use the
ceilToDouble()
method to get its ceiling value as a double. - We then print the result to standard output.
Dart Program
void main() {
num integerNum = 7.0;
double ceilValue = integerNum.ceilToDouble();
print('Ceil to double of $integerNum: $ceilValue');
}
Output
Ceil to double of 7: 7
Summary
In this Dart tutorial, we learned about ceilToDouble() method of num: the syntax and few working examples with output and detailed explanation for each example.