Convert float to int in Julia Lang
I think you are looking for floor
:
julia> x = 1.23455
1.23455
julia> floor(x)
1.0
julia> y = x - floor(x)
0.23455000000000004
Combining the previous answers:
julia> int(x) = floor(Int, x)
int (generic function with 1 method)
julia> int(3.14)
3
julia> int(3.94)
3
It is possible that you are looking for trunc
. It depends on what you mean by the decimal part. This is the difference between trunc
and floor
:
julia> trunc(Int, 1.2)
1
julia> trunc(Int, -1.2)
-1
julia> floor(Int, 1.2)
1
julia> floor(Int, -1.2)
-2