Open In App

Scala Long toByte() method with example

Last Updated : 03 Nov, 2019
Improve
Improve
Like Article
Like
Save
Share
Report

The toByte() method is utilized to convert the specified number into Byte data type value. The range of the byte data type is from -128 to 127.

Method Definition: (Number).toByte

Return Type: It returns the converted byte datatype value.

Example 1:




// Scala program of Long toByte()
// method
  
// Creating object
object Test
{
  
    // Main method
    def main(args : Array[String])
    {
  
        // Implementing toByte method
        val res = (25).toByte
  
        // Displays output
        println(res)
    }
}


Output:

25

Example 2:




// Scala program of Long toByte()
// method
  
// Creating object
object Test
{
  
    // Main method
    def main(args : Array[String])
    {
  
        // Implementing toByte method
        val res = (129).toByte
  
        // Displays output
        println(res)
    }
}


Output:

-127


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

Similar Reads