Dart double isFinite
Syntax & Examples
double.isFinite property
The `isFinite` property checks if the number is finite.
Syntax of double.isFinite
The syntax of double.isFinite property is:
bool isFinite This isFinite property of double true if the number is finite; otherwise, false.
Return Type
double.isFinite returns value of type bool.
✐ Examples
1 Check if a finite number is finite
In this example,
- We define a double
numwith a finite value of3.14. - We access the
isFiniteproperty to check ifnumis finite. - We print the result to standard output.
Dart Program
void main() {
double num = 3.14;
bool isNumFinite = num.isFinite;
print('Is 3.14 finite? $isNumFinite');
}Output
Is 3.14 finite? true
2 Check if infinity is finite
In this example,
- We define a double
numwith a value of positive infinity. - We access the
isFiniteproperty to check ifnumis finite. - We print the result to standard output.
Dart Program
void main() {
double num = double.infinity;
bool isNumFinite = num.isFinite;
print('Is infinity finite? $isNumFinite');
}Output
Is infinity finite? false
3 Check if NaN is finite
In this example,
- We define a double
numwith a value of NaN. - We access the
isFiniteproperty to check ifnumis finite. - We print the result to standard output.
Dart Program
void main() {
double num = double.nan;
bool isNumFinite = num.isFinite;
print('Is NaN finite? $isNumFinite');
}Output
Is NaN finite? false
Summary
In this Dart tutorial, we learned about isFinite property of double: the syntax and few working examples with output and detailed explanation for each example.