Dart num isFinite
Syntax & Examples


num.isFinite property

The `isFinite` property in Dart checks if a number is finite.


Syntax of num.isFinite

The syntax of num.isFinite property is:

 bool isFinite 

This isFinite property of num true if the number is finite; otherwise, false.

Return Type

num.isFinite returns value of type bool.



✐ Examples

1 Checking finiteness of integers and decimals

In this example,

  1. We define two variables, number1 and number2, with values 10 and 3.5 respectively.
  2. We check their finiteness using the isFinite property and store the results in result1 and result2.
  3. We print the results to standard output.

Dart Program

void main() {
  num number1 = 10;
  num number2 = 3.5;
  bool result1 = number1.isFinite;
  bool result2 = number2.isFinite;
  print('Is $number1 finite? $result1');
  print('Is $number2 finite? $result2');
}

Output

Is 10 finite? true
Is 3.5 finite? true

2 Checking finiteness of infinity

In this example,

  1. We create a variable number with the value double.infinity, representing infinity.
  2. We use the isFinite property to check its finiteness and store the result in result.
  3. We print the result to standard output.

Dart Program

void main() {
  num number = double.infinity;
  bool result = number.isFinite;
  print('Is $number finite? $result');
}

Output

Is infinity finite? false

3 Checking finiteness of NaN

In this example,

  1. We create a variable number with the value double.nan, representing Not-a-Number (NaN).
  2. We use the isFinite property to check its finiteness and store the result in result.
  3. We print the result to standard output.

Dart Program

void main() {
  num number = double.nan;
  bool result = number.isFinite;
  print('Is $number finite? $result');
}

Output

Is NaN finite? false

Summary

In this Dart tutorial, we learned about isFinite property of num: the syntax and few working examples with output and detailed explanation for each example.