Is there a way to convert a floating number to int in Julia? I'm trying to convert a floating point number to a fixed precision number with the decimal part represented as 8bit integer. In order to do this, I need to truncate just the decimal part of the number and I figured the best way to do this would be to subtract the converted integer of x from floating point x:
x = 1.23455 y = x - Int(x) println(y)
y = 0.23455
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With