This is the result of having different ways to show the results. When printing an array, a “compact” representation is chosen. The same is happening in the case of the random array:

(@v1.7) julia> z=rand(4,4);
(@v1.7) julia> a=sum(z,dims=1);
(@v1.7) julia> show(stdout, a) # force "non-compact" output
[1.6704264853429793 2.1144597128383222 1.623925634087594 2.104374970136207]
(@v1.7) julia> show(stdout, "text/plain", a)
1×4 Matrix{Float64}:
1.67043 2.11446 1.62393 2.10437

I understand that. But why in my first example is the compact representation so compact (just one decimal place instead of, say, four)? Shouldn’t the compact representation always have the same number of decimal places (I’m thinking of the Matlab commands format short and format long)?

In both cases they are printed with 6 significant digits.

In floating-point arithmetic it generally makes more sense to think in terms of significant digits than decimal places, because the numbers can be very large (1e300) or very small (1e-300).

Slightly off-topic, but I’d recommend not using a floating point data type for financial calculations/display, as some operations (e.g. adding a very small amount in cents to a very large amount in dollars) can make the cents vanish purely due to how floating point math inherently works. Different order of summations of floating point values can also lead to different results, which is probably not desirable.

“Vanishing” cents will only happen from a single addition in double precision for amounts exceeding roughly 90 trillion dollars, at which point the importance of individual pennies becomes questionable. However, because decimal values are not exactly represented, instead of 99 cents you might have 98.99999999999999… cents.

In situations where you absolutely have to preserve cents exactly (e.g. because of a fiduciary requirement), you can use decimal floating point, which preserves the wide dynamic range and sensible roundoff semantics of floating point (unlike fixed point) while providing exact representations of decimal values.