trunc()
是 julia 中的一个内置函数,用于返回与指定值x相同类型的最近整数值,其绝对值小于或等于x 。
Syntax: trunc(x)
Parameters:
- x: Specified value.
Returns: It returns the nearest integral value of the same type as the specified value x whose absolute value is less than or equal to 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