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
Pingback: Dart Programming - ceil Method | Adglob Infosystem Pvt Ltd
Pingback: Dart Programming - Numbers | Adglob Infosystem Pvt Ltd