📜  在 Julia 中获取 x 最接近的整数值——trunc() 方法

📅  最后修改于: 2021-11-25 04:49:50             🧑  作者: Mango

trunc()是 julia 中的一个内置函数,用于返回与指定值x相同类型的最近整数值,其绝对值小于或等于x

示例 1:

# Julia program to illustrate 
# the use of trunc() method
  
# Getting the nearest integral value 
# of the same type as the specified value 
# x whose absolute value is less
# than or equal to x
println(trunc(3))
println(trunc(0.5))
println(trunc(3.9))

输出:

3
0.0
3.0

示例 2:

# Julia program to illustrate 
# the use of trunc() method
  
# Getting the nearest integral value 
# of the same type as the specified value 
# x whose absolute value is less
# than or equal to x
println(trunc(0))
println(trunc(2))
println(trunc(2.1))
println(trunc(2.5))
println(trunc(2.9))

输出:

0
2
2.0
2.0
2.0