Getting the nearest integral value of x in Julia – trunc() Method
Last Updated :
21 Apr, 2020
The trunc()
is an inbuilt function in julia which is used to return the nearest integral value of the same type as the specified value x whose absolute value is less than or equal to x.
Syntax: trunc(x)
Parameters:
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.
Example 1:
println(trunc( 3 ))
println(trunc( 0.5 ))
println(trunc( 3.9 ))
|
Output:
3
0.0
3.0
Example 2:
println(trunc( 0 ))
println(trunc( 2 ))
println(trunc( 2.1 ))
println(trunc( 2.5 ))
println(trunc( 2.9 ))
|
Output:
0
2
2.0
2.0
2.0
Share your thoughts in the comments
Please Login to comment...