Incorrect display of Array{Float64,2} numbers

Dear all, I am just starting to use Julia and I run into the following issue [Julia Version 1.4.1 (2020-04-14)]:

julia> arr = [-498796.2749933266 408222.59838380764 -583210.404155956 266966.3188608052];

julia> arr
1×4 Array{Float64,2}:
 -498796.0  408223.0  -583210.0  266966.0

julia> print(arr)
[-498796.2749933266 408222.59838380764 -583210.404155956 266966.3188608052]

Notice that in the second output, all numbers are incorrectly rounded to “.0”.

But with 1D array this works as expected:

julia> arr = [-498796.2749933266; 408222.59838380764; -583210.404155956; 266966.3188608052];

julia> arr
4-element Array{Float64,1}:
 -498796.2749933266
  408222.59838380764
 -583210.404155956
  266966.3188608052

Am I doing something wrong, or should I report a bug?

It’s just printing them in a compact form, so that more columns can fit into the screen. (For example rand(9,9) fits into a window 100 characters wide.) As you’ve noticed, it doesn’t do this for vectors, since there is nothing to be gained.

That’s true, but the .0 is just wrong. Displaying -498796 would be correct (rounding to the nearest integer), but displaying -498796.0 is wrong–it should be -498796.3.

I’ve verified that this exists in Julia 1.4.2 and in the 1.5 beta.

2 Likes

I’ve opened an issue: https://github.com/JuliaLang/julia/issues/36234

Oh I see, sorry, the complaint is that it’s rounding to 0 digits when there is space for 1:

julia> round(arr[2], digits=0)
408223.0

julia> round(arr[2], digits=1)
408222.6

Yeah, exactly. It’s that when we round to 0 digits, we still have a Float64, and an integral Float64 is always printed with .0. That implies (to my human brain) that .0 is a significant digit of the value, but that’s not the case.

The solution might be to never round to exactly 0 digits when printing in compact mode.

4 Likes