Unexpected Behaviour of the Rounding Function

I think that’s because the decimal value 0.575 is not exactly represented in binary floating-point arithmetic. It’s actually the value:

julia> big(0.575)
0.5749999999999999555910790149937383830547332763671875

which is < 0.575:

julia> 0.575 < 575//1000
true

so it correctly rounds down to 0.57. See PSA: floating-point arithmetic

The surprising thing to me is that 0.585 rounds up, since we also have:

julia> big(0.585)
0.58499999999999996447286321199499070644378662109375

julia> 0.585 < 585//1000
true
2 Likes