带有示例的 Scala Float toByte() 方法
toByte()方法用于将指定的数字转换为 Byte 数据类型值。字节数据类型的范围是 -128 到 127。
Method Definition: (Number).toByte
Return Type: It returns the converted byte datatype value.
示例 #1:
// Scala program of Float toByte()
// method
// Creating object
object GfG
{
// Main method
def main(args:Array[String])
{
// Applying toByte method
val result = (66).toByte
// Displays output
println(result)
}
}
输出:
66
示例 #2:
// Scala program of Float toByte()
// method
// Creating object
object GfG
{
// Main method
def main(args:Array[String])
{
// Applying toByte method
val result = (129).toByte
// Displays output
println(result)
}
}
输出:
-127