Short, a 16-bit signed integer (equivalent to Java’s short primitive type) is a subtype of scala.AnyVal. The toShort() method is utilized to convert the specified number into Short datatype value.
Method Definition: (Number).toShort
Return Type: It returns converted Short value.
Example #1:
// Scala program of Short toShort() // method // Creating object object GfG
{ // Main method
def main(args : Array[String])
{
// Applying toShort method
val result = ( 13 ).toShort
// Displays output
println(result)
}
} |
Output:
13
Example #2:
// Scala program of Short toShort() // method // Creating object object GfG
{ // Main method
def main(args : Array[String])
{
// Applying toShort method
val result = ( 123.4 ).toShort
// Displays output
println(result)
}
} |
Output:
123