Scala Float compareTo() method with example
Last Updated :
29 Oct, 2019
The compareTo() method is utilized to returns 0 if the first number is equal to the second number, 1 if the first number is greater then the second number and finally -1 if the first number is less than the second number.
Method Definition: (First_Number).compareTo(Second_Number)
Return Type: It returns 0 if the first number is equal to the second number, 1 if the first number is greater then the second number and finally -1 if the first number is less than the second number.
Example #1:
object GfG
{
def main(args : Array[String])
{
val m 1 = 3.4
val result = m 1 .compareTo( 3.4 )
println(result)
}
}
|
Example #2:
object GfG
{
def main(args : Array[String])
{
val m 1 = 3.4
val result = m 1 .compareTo( 2.4 )
println(result)
}
}
|
Example #3:
object GfG
{
def main(args : Array[String])
{
val m 1 = 3.4
val result = m 1 .compareTo( 9.5 )
println(result)
}
}
|
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...