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