Open In App

Scala Float toShort() method with example

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

The toShort() method is utilized to convert the specified number into Short data type value. The range of the byte data type is from -32, 768 to 32, 767

Method Definition: (Number).toShort

Return Type: It returns the converted Short datatype value.

Example #1:




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


Output:

199

Example #2:




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


Output:

-32737


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads