Scala Float toFloat() 方法与示例
toFloat()方法用于将指定的数字转换为浮点值。
Method Definition: (Number).toFloat
Return Type: It returns the converted float value.
示例 #1:
// Scala program of Float toFloat()
// method
// Creating object
object GfG
{
// Main method
def main(args:Array[String])
{
// Applying toFloat method
val result = (9).toFloat
// Displays output
println(result)
}
}
输出:
9.0
示例 #2:
// Scala program of Float toFloat()
// method
// Creating object
object GfG
{
// Main method
def main(args:Array[String])
{
// Applying toFloat method
val result = (0).toFloat
// Displays output
println(result)
}
}
输出:
0.0
示例#3:
// Scala program of Float toFloat()
// method
// Creating object
object GfG
{
// Main method
def main(args:Array[String])
{
// Applying toFloat method
val result = (4.7).toFloat
// Displays output
println(result)
}
}
输出:
4.7