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
Int(x)
will return anInexact error
unlessx
is a whole number expressed asFloat64
, e.g.1.0
or-44.0
. Also, I can't tell what you're actually after based on the question. Your wording makes it sound like you want the decimal portion of aFloat64
, expressed as anInt8
. Is this right? That is an odd request, particularly given that for your example number1.23455
, the decimal portion asInt64
is23455
, but this is obviously much too large to be expressed as anInt8
. – Colin T Bowers