# Why there is no method matching round(::Type{Int64}, ::BitArray{1})

**URL:** <https://discourse.julialang.org/t/why-there-is-no-method-matching-round-type-int64-bitarray-1/32163>\
**Category:** General Usage\
**Created:** [December 11, 2019, 6:24pm UTC](https://discourse.julialang.org/t/why-there-is-no-method-matching-round-type-int64-bitarray-1/32163 "2019-12-11T18:24:55Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![marouane1994](https://avatars.discourse-cdn.com/v4/letter/m/74df32/32.png) [@marouane1994](https://discourse.julialang.org/u/marouane1994)\
**Post date:** [December 11, 2019, 6:24pm UTC](https://discourse.julialang.org/t/why-there-is-no-method-matching-round-type-int64-bitarray-1/32163/1 "2019-12-11T18:24:55Z")

</div>

let us suppose that i want to perform this following operation:  
`round(Int,[2.3,2.5,8.9].>0)`  
and then i get a `MethodError` saying that:  
`ERROR: MethodError: no method matching round(::Type{Int64}, ::BitArray{1})`.  
is there any other way to perform this operation?

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [December 11, 2019, 6:29pm UTC](https://discourse.julialang.org/t/why-there-is-no-method-matching-round-type-int64-bitarray-1/32163/2 "2019-12-11T18:29:05Z")

</div>

I’m not sure I understand the operation you’re trying to perform - could you clarify the expected output?

`[2.3,2.5,8.9].>0` should give you a Bitarray with all 1’s, what to you expect round to do with that?

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [December 11, 2019, 6:38pm UTC](https://discourse.julialang.org/t/why-there-is-no-method-matching-round-type-int64-bitarray-1/32163/3 "2019-12-11T18:38:09Z")

</div>

You might be looking for

```julia
julia> Int.([2.9,3.9,4.5].>0)
3-element Array{Int64,1}:
 1
 1
 1

```

---

<div class="post-metadata">

**Author:** ![DNF](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dnf/32/10191_2.png) [@DNF](https://discourse.julialang.org/u/DNF)\
**Post date:** [December 11, 2019, 7:04pm UTC](https://discourse.julialang.org/t/why-there-is-no-method-matching-round-type-int64-bitarray-1/32163/4 "2019-12-11T19:04:59Z")

</div>

> [@marouane1994](#):
>
> ```julia
> round(Int,[2.3,2.5,8.9].>0)
> 
> ```

You cannot round a vector to an `Int`. But you _can_ round each element of the vector to an `Int`:

```julia
julia> round.(Int,[2.3,2.5,8.9].>0)
3-element Array{Int64,1}:
 1
 1
 1

```

---

<div class="post-metadata">

**Author:** ![marouane1994](https://avatars.discourse-cdn.com/v4/letter/m/74df32/32.png) [@marouane1994](https://discourse.julialang.org/u/marouane1994)\
**Post date:** [December 12, 2019, 5:32pm UTC](https://discourse.julialang.org/t/why-there-is-no-method-matching-round-type-int64-bitarray-1/32163/5 "2019-12-12T17:32:56Z")

</div>

yes i was trying to round each element of the array that’s what i wanted to perform

---

<div class="post-metadata">

**Author:** ![klaff](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/klaff/32/7637_2.png) [@klaff](https://discourse.julialang.org/u/klaff)\
**Post date:** [December 12, 2019, 6:12pm UTC](https://discourse.julialang.org/t/why-there-is-no-method-matching-round-type-int64-bitarray-1/32163/6 "2019-12-12T18:12:15Z")

</div>

Did you also want to filter on non-negative values? (Your original has a `>0` comparison and I’m not sure why it was there.)

So perhaps one of these:

```julia
julia> round.(Int, [2.3,2.5, 8.9])
3-element Array{Int64,1}:
 2
 2
 9

julia> [round(Int,x) for x ∈ [2.3,2.5,8.9,-5.2] if x>0]
3-element Array{Int64,1}:
 2
 2
 9

```

---

<div class="post-metadata">

**Author:** ![marouane1994](https://avatars.discourse-cdn.com/v4/letter/m/74df32/32.png) [@marouane1994](https://discourse.julialang.org/u/marouane1994)\
**Post date:** [December 13, 2019, 9:25am UTC](https://discourse.julialang.org/t/why-there-is-no-method-matching-round-type-int64-bitarray-1/32163/7 "2019-12-13T09:25:08Z")

</div>

actually my aim is to return all the positive numbers to 1, and the negatives in that array should return 0

---

<div class="post-metadata">

**Author:** ![klaff](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/klaff/32/7637_2.png) [@klaff](https://discourse.julialang.org/u/klaff)\
**Post date:** [December 13, 2019, 2:36pm UTC](https://discourse.julialang.org/t/why-there-is-no-method-matching-round-type-int64-bitarray-1/32163/8 "2019-12-13T14:36:09Z")

</div>

So how about this:

```julia
julia> [x>0 ? 1 : 0 for x ∈ [2.3,2.5,8.9,-5.2]]
4-element Array{Int64,1}:
 1
 1
 1
 0

```

or equivalently but maybe better for reuse or composition:

```julia
julia> f(x) = x>0 ? 1 : 0
f (generic function with 1 method)

julia> f.([2.3,2.5, 8.9,-5.2])
4-element Array{Int64,1}:
 1
 1
 1
 0

```

and if you want your answer in place (replacing your input data) rather than making a new array you can use the element-wise assignment operator `.=`:

```julia
julia> a1 = [2.3,2.5, 8.9,-5.2]
4-element Array{Float64,1}:
  2.3
  2.5
  8.9
 -5.2

julia> a1 .=f.(a1)
4-element Array{Float64,1}:
 1.0
 1.0
 1.0
 0.0

```

Note that in the last one, because the array already exists with a type of `Float64`, the answers were converted to that type.

---

<div class="post-metadata">

**Author:** ![marouane1994](https://avatars.discourse-cdn.com/v4/letter/m/74df32/32.png) [@marouane1994](https://discourse.julialang.org/u/marouane1994)\
**Post date:** [December 13, 2019, 8:02pm UTC](https://discourse.julialang.org/t/why-there-is-no-method-matching-round-type-int64-bitarray-1/32163/9 "2019-12-13T20:02:15Z")

</div>

all of these solutions are possible it’s just you have to do it in the right way that goes well with the entire code

---

<div class="post-metadata">

**Author:** ![Freya\_the\_Goddess](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/freya_the_goddess/32/36835_2.png) [@Freya\_the\_Goddess](https://discourse.julialang.org/u/Freya_the_Goddess)\
**Post date:** [July 28, 2022, 6:26am UTC](https://discourse.julialang.org/t/why-there-is-no-method-matching-round-type-int64-bitarray-1/32163/10 "2022-07-28T06:26:21Z")

</div>

Hi @nilshg ,

I saw this topic, and currently have facing the similar problem.

I have this vector of LU decomposition:

**3-element Vector{Float64}:**  
\*\* 1.7499999999999998\*\*  
\*\* 0.9999999999999998\*\*  
\*\* -0.4999999999999999\*\*

I do this:

```julia
#Change result to Int
I = Int.(x.>0)

```

Get this:  
**3-element Vector{Int64}:**  
\*\* 1\*\*  
\*\* 1\*\*  
\*\* 0\*\*

Since -0.499n9999999 is too far to be rounded to 0, I want to round it to 3 significant digits, try this:

```julia
round(I; digits = 3)

```

failed:  
**MethodError: no method matching round(::Vector{Int64}; digits=3)**  
**Closest candidates are:**

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [July 28, 2022, 9:27am UTC](https://discourse.julialang.org/t/why-there-is-no-method-matching-round-type-int64-bitarray-1/32163/11 "2022-07-28T09:27:05Z")

</div>

Hi Freya, probably best to start a new topic rather than resurrect 3-year old threads and ping everyone who answered here, but in this specific case the solution already provided above is also the solution to your problem: `round` works on scalars, so if you want to apply it elementwise to an array you need to do `round.(I)`.

---

<div class="post-metadata">

**Author:** ![Freya\_the\_Goddess](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/freya_the_goddess/32/36835_2.png) [@Freya\_the\_Goddess](https://discourse.julialang.org/u/Freya_the_Goddess)\
**Post date:** [August 1, 2022, 3:57am UTC](https://discourse.julialang.org/t/why-there-is-no-method-matching-round-type-int64-bitarray-1/32163/12 "2022-08-01T03:57:19Z")

</div>

Thanks @nilshg , sorry for pinging after 3 years this thread is dead. I thought it is better to ask here than start a new one, guess I was wrong.

Thanks again your guide on Jupyter Notebook helps me to make Julia Kernel alive again  
([https://stackoverflow.com/questions/62071591/kernel-error-using-julia-on-jupyter-notebook](https://stackoverflow.com/questions/62071591/kernel-error-using-julia-on-jupyter-notebook))
