# How to prevent type conversion for single value array?

**URL:** <https://discourse.julialang.org/t/how-to-prevent-type-conversion-for-single-value-array/67632>\
**Category:** General Usage\
**Tags:** pluto, type-stability\
**Created:** [September 3, 2021, 9:59am UTC](https://discourse.julialang.org/t/how-to-prevent-type-conversion-for-single-value-array/67632 "2021-09-03T09:59:55Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Minimum-Pollution-96](https://avatars.discourse-cdn.com/v4/letter/m/a88e4f/32.png) [@Minimum-Pollution-96](https://discourse.julialang.org/u/Minimum-Pollution-96)\
**Post date:** [September 3, 2021, 9:59am UTC](https://discourse.julialang.org/t/how-to-prevent-type-conversion-for-single-value-array/67632/1 "2021-09-03T09:59:56Z")

</div>

I am trying to create a single valued array called `xs` in which I am later pushing in values.

```julia
xs = [x0,]

```

where `x0` is obtained through a slider in Pluto notebook as follows.

```julia
@bind x0 Slider(0.0:0.01:0.99, show_value=true)

```

However, when `x0` is set as `0.0`, it results in the `xs` being created as `Int64` array which raises error while pushing further values into it.

```julia
InexactError: Int64(0.09685647168069829)
    Int64@float.jl:723[inlined]
    convert@number.jl:7[inlined]
    push!(::Vector{Int64}, ::Float64)@array.jl:928
    top-level scope@Local: 10[inlined]

```

Shouldn’t the `xs` be created as `Float64` array since `x0` is of that type? Also, is there a way to prevent this issue?

---

<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:** [September 3, 2021, 10:20am UTC](https://discourse.julialang.org/t/how-to-prevent-type-conversion-for-single-value-array/67632/2 "2021-09-03T10:20:10Z")

</div>

> [@Minimum-Pollution-96](#):
>
> `@bind x0 Slider(0.0:0.01:0.99, show_value=true)`

Seems to me a bug in PlutoUI, I can reproduce this - initially the value is 0.0, but when the slider is moved away from zero and back down it switches to Int64. A simple workaround is to actually fix the type of the Array:

```julia
xs = Float64[x0,]

```

EDIT: looks like this is a known issue, with the problem being on the JS side, see here: [Instability in return type of PlutoUI.Slider · Issue #64 · JuliaPluto/PlutoUI.jl · GitHub](https://github.com/fonsp/PlutoUI.jl/issues/64)

---

<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:** [September 3, 2021, 10:35am UTC](https://discourse.julialang.org/t/how-to-prevent-type-conversion-for-single-value-array/67632/3 "2021-09-03T10:35:15Z")

</div>

> [@Minimum-Pollution-96](#):
>
> `xs = [x0,]`

Incidentally, there’s no need for the comma, `[0.0]` works. The trailing comma is something that you need for tuples, because parentheses have several meanings.

---

<div class="post-metadata">

**Author:** ![Minimum-Pollution-96](https://avatars.discourse-cdn.com/v4/letter/m/a88e4f/32.png) [@Minimum-Pollution-96](https://discourse.julialang.org/u/Minimum-Pollution-96)\
**Post date:** [September 3, 2021, 1:26pm UTC](https://discourse.julialang.org/t/how-to-prevent-type-conversion-for-single-value-array/67632/4 "2021-09-03T13:26:54Z")

</div>

Oh, okay! I had mistook this as syntax. Thanks!

---

<div class="post-metadata">

**Author:** ![Minimum-Pollution-96](https://avatars.discourse-cdn.com/v4/letter/m/a88e4f/32.png) [@Minimum-Pollution-96](https://discourse.julialang.org/u/Minimum-Pollution-96)\
**Post date:** [September 3, 2021, 1:27pm UTC](https://discourse.julialang.org/t/how-to-prevent-type-conversion-for-single-value-array/67632/5 "2021-09-03T13:27:26Z")

</div>

Thank you!
