Dart Programming – compareTo Method

  • Post author:
  • Post category:Dart
  • Post comments:2 Comments
dart programming compareto method

In this guide, we will discuss CompareTo method in Dart Programming. 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

Next Topic : Click Here

This Post Has 2 Comments

Leave a Reply