Open In App

Scala Float signum() method with example

Last Updated : 29 Oct, 2019
Improve
Improve
Like Article
Like
Save
Share
Report

The signum() method is utilized to return 1 for positive specified number, -1 for negative specified number and 0 for 0 specified value.

Method Definition: (Value).signum

Return Type: It returns 1 for positive specified number, -1 for negative specified number and 0 for 0 specified value.

Example #1:




// Scala program of Float signum()
// method
  
// Creating object
object GfG
  
    // Main method
    def main(args:Array[String])
    {
      
        // Applying signum method
        val result = (5).signum
          
        // Displays output
        println(result)
      
    }


Output:

1

Example #2:




// Scala program of Float signum()
// method
  
// Creating object
object GfG
  
    // Main method
    def main(args:Array[String])
    {
      
        // Applying signum method
        val result = (-5).signum
          
        // Displays output
        println(result)
      
    }


Output:

-1

Example #3:




// Scala program of Float signum()
// method
  
// Creating object
object GfG
  
    // Main method
    def main(args:Array[String])
    {
      
        // Applying signum method
        val result = (0).signum
          
        // Displays output
        println(result)
      
    }


Output:

0


Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads