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

**URL:** <https://discourse.julialang.org/t/how-do-you-round-0-1-and-0-1-to-0-0-not-0-0-and-0-0/108731>\
**Category:** General Usage\
**Created:** [January 12, 2024, 2:54pm UTC](https://discourse.julialang.org/t/how-do-you-round-0-1-and-0-1-to-0-0-not-0-0-and-0-0/108731 "2024-01-12T14:54:46Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![BMval](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bmval/32/7647_2.png) [@BMval](https://discourse.julialang.org/u/BMval)\
**Post date:** [January 12, 2024, 2:54pm UTC](https://discourse.julialang.org/t/how-do-you-round-0-1-and-0-1-to-0-0-not-0-0-and-0-0/108731/1 "2024-01-12T14:54:46Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![mkitti](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkitti/32/12459_2.png) [@mkitti](https://discourse.julialang.org/u/mkitti)\
**Post date:** [January 12, 2024, 3:07pm UTC](https://discourse.julialang.org/t/how-do-you-round-0-1-and-0-1-to-0-0-not-0-0-and-0-0/108731/2 "2024-01-12T15:07:39Z")

</div>

Short answer:

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

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

```

---

<div class="post-metadata">

**Author:** ![sijo](https://avatars.discourse-cdn.com/v4/letter/s/da6949/32.png) [@sijo](https://discourse.julialang.org/u/sijo)\
**Post date:** [January 12, 2024, 3:10pm UTC](https://discourse.julialang.org/t/how-do-you-round-0-1-and-0-1-to-0-0-not-0-0-and-0-0/108731/3 "2024-01-12T15:10:52Z")

</div>

Another option is to convert the negative zeros to positive:

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

```

---

<div class="post-metadata">

**Author:** ![Salmon](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/salmon/32/22968_2.png) [@Salmon](https://discourse.julialang.org/u/Salmon)\
**Post date:** [January 12, 2024, 3:12pm UTC](https://discourse.julialang.org/t/how-do-you-round-0-1-and-0-1-to-0-0-not-0-0-and-0-0/108731/4 "2024-01-12T15:12:54Z")

</div>

What about defining your own rounding function?

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

```
