Dart Programming - compareTo Method



It returns an integer indicating the relationship between the two numbers.

Syntax

Number.compareTo(x)

Parameter

  • x − represents a number.

Return Value

Returns the value −

  • 0 − if the values are equal.

  • 1 − if the current number object is greater than the specified numeric value.

  • -1 − if the current number object is lesser than the specified numeric value.

Example

void main() { 
   var a = 2.4; 
   print(a.compareTo(12)); 
   print(a.compareTo(2.4)); 
   print(a.compareTo(0)); 
} 

It will produce the following output −.

-1 
0 
1
dart_programming_numbers.htm
Advertisements