带有示例的 Scala Float toShort() 方法
toShort()方法用于将指定的数字转换为 Short 数据类型值。字节数据类型的范围是-32, 768 到 32, 767
Method Definition: (Number).toShort
Return Type: It returns the converted Short datatype value.
示例 #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)
}
}
输出:
199
示例 #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)
}
}
输出:
-32737