Getting the nearest integral value of x in Julia – trunc() Method
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:
- 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.
Example 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 xprintln(trunc(3))println(trunc(0.5))println(trunc(3.9)) |
Output:
3 0.0 3.0
Example 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 xprintln(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


