Scala Int round() 方法与示例
round()方法用于返回指定 int 值的舍入值。此方法用于避免通过 Float 绕道而导致的意外精度损失。
Method Definition: def round: Int
Return Type: It returns the rounded value of the specified int value.
示例 #1:
// Scala program of Int round
// method
// Creating object
object GfG
{
// Main method
def main(args:Array[String])
{
// Applying round method
val result = (5).round
// Displays output
println(result)
}
}
输出:
5
示例 #2:
// Scala program of Int round
// method
// Creating object
object GfG
{
// Main method
def main(args:Array[String])
{
// Applying round method
val result = (5.8).round
// Displays output
println(result)
}
}
输出:
6