Julia Int function

What errors? Int only works if the numbers can be actually converted to Integers without loss of precision:

julia> Int(1.0)
1

julia> Int(1.1)
ERROR: InexactError: Int64(1.1)
Stacktrace:
 [1] Int64(x::Float64)
   @ Base ./float.jl:788
 [2] top-level scope
   @ REPL[62]:1

Maybe you want round instead:

julia> round(Int, 1.1)
1

I don’t think anything changed here.

3 Likes