How do you round -0.1 and +0.1 to 0.0? not -0.0 and 0.0

The function round.([0.1 ,-0.1]) returns minus zeros and positive zero.
Is there a way, that both will be just zero (positive).

I have this issue, since later I use unique([-0.0,0.0]), which give again two zeros: -0.0 and 0.0.

Thanks in advance.

Short answer:

If you want to round to an integer, you can do the following:

julia> round.(Int, [-0.1,0.1])
2-element Vector{Int64}:
 0
 0
1 Like

Another option is to convert the negative zeros to positive:

julia> round.([0.1 ,-0.1]) .+ 0
2-element Vector{Float64}:
 0.0
 0.0
2 Likes

What about defining your own rounding function?

function roundzero(x; kwargs...)
  xrd = round(x;kwargs...)
  xrd = ifelse(==(-zero(xrd)),zero(xrd))
  return xrd
end