带有示例的 Scala Double -(x: Long) 方法
在 Scala 中,Double 是一个 64 位浮点数,相当于 Java 的 double 基本类型。 -(x: Long)方法用于获取给定 Double 和 Long 值的差异。
Method Definition – def -(x: Long): Double
Returns – Returns the difference of this value and x.
示例 #1:
// Scala program to explain working
// of Double -(x: Long) function
// Creating object
object GfG
{
// Main method
def main(args:Array[String])
{
// Applying -(x: Long) function
val result = (66.01230).toDouble.- (60:Long)
// Displays output
println(result)
}
}
输出:
6.012299999999996
示例 #2:
// Scala program to explain working
// of Double -(x: Long) function
// Creating object
object GfG
{
// Main method
def main(args:Array[String])
{
// Applying -(x: Long) function
val result = 11.86000000.toDouble.- (10:Long)
// Displays output
println(result)
}
}
输出:
1.8599999999999994