Dart int isFinite
Syntax & Examples
int.isFinite property
The `isFinite` property in Dart returns true if the number is finite; otherwise, it returns false.
Syntax of int.isFinite
The syntax of int.isFinite property is:
bool isFinite This isFinite property of int true if the number is finite; otherwise, false.
Return Type
int.isFinite returns value of type bool.
✐ Examples
1 Check if a finite number is finite
In this example,
- We assign the value
3.14to the double variablenum1. - We check if
num1is finite using theisFiniteproperty. - We print the result to standard output.
Dart Program
void main() {
double num1 = 3.14;
bool result1 = num1.isFinite;
print('Is $num1 finite? $result1');
}Output
Is 3.14 finite? true
2 Check if positive infinity is finite
In this example,
- We assign
double.infinityto the double variablenum2. - We check if
num2is finite using theisFiniteproperty. - We print the result to standard output.
Dart Program
void main() {
double num2 = double.infinity;
bool result2 = num2.isFinite;
print('Is $num2 finite? $result2');
}Output
Is infinity finite? false
3 Check if NaN is finite
In this example,
- We assign
double.nanto the double variablenum3. - We check if
num3is finite using theisFiniteproperty. - We print the result to standard output.
Dart Program
void main() {
double num3 = double.nan;
bool result3 = num3.isFinite;
print('Is $num3 finite? $result3');
}Output
Is NaN finite? false
Summary
In this Dart tutorial, we learned about isFinite property of int: the syntax and few working examples with output and detailed explanation for each example.