# Float array "limitation"?

**URL:** <https://discourse.processing.org/t/float-array-limitation/43469>\
**Category:** Beginners\
**Created:** [December 13, 2023, 7:18pm UTC](https://discourse.processing.org/t/float-array-limitation/43469 "2023-12-13T19:18:03Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![boytedinho](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/boytedinho/32/19068_2.png) [@boytedinho](https://discourse.processing.org/u/boytedinho)\
**Post date:** [December 13, 2023, 7:18pm UTC](https://discourse.processing.org/t/float-array-limitation/43469/1 "2023-12-13T19:18:03Z")

</div>

Hi there!

I’m just playing around with arrays, learning how to work with them, but there’s one problem happening and I can’t figure it out why

The program is written as follows:

```auto
float[] bar = new float[100];

void setup() {
  size(1080, 1080);
  for (int i = 0; i < bar.length; i++) {
    bar[i] = random(200,height-200);
  }
}

void draw() {
  float x = 0;
  
  background(0);
  fill(255);
  stroke(255);

  for (int i = 0; i < bar.length; i++) {
    float spacing = width / bar.length;
    rect(x, 0, spacing, bar[i]);
    x = x + spacing;
  }
}

void mousePressed() {
  for (int i = 0; i < bar.length; i++) {
    bar[i] = random(200,height-200);
  }
}

```

it should draw these white bars all around the canvas size, but it is not working well when I set widths and heights higher than 1000 (if it’s 1080, it only works as planned if I change the array’s index to a maximum of 45 elements).

Thats the result with the missing part:

 ![bars](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/f/1/f1bcac7bb79da09b3ce67762d672643661aeb426.png)

---

<div class="post-metadata">

**Author:** ![mnse](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/mnse/32/16520_2.png) [@mnse](https://discourse.processing.org/u/mnse)\
**Post date:** [December 13, 2023, 7:59pm UTC](https://discourse.processing.org/t/float-array-limitation/43469/2 "2023-12-13T19:59:22Z")

</div>

Hi @boytedinho,

Try changing this line

> [@boytedinho](#):
>
> `float spacing = width / bar.length;`

`float spacing = width / float(bar.length);`

Btw. You don’t need to calculate that inside the loop…

Cheers  
— mnse

PS: [Troubleshooting · processing/processing Wiki · GitHub](https://github.com/processing/processing/wiki/Troubleshooting#why-does-2--5--0-instead-of-04)

> **[Integer division: How do you produce a double?](https://www.w3docs.com/snippets/java/integer-division-how-do-you-produce-a-double.html)**
>
> In Java, integer division always produces an integer result, even if the dividend is a floating-point number.

---

<div class="post-metadata">

**Author:** ![boytedinho](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/boytedinho/32/19068_2.png) [@boytedinho](https://discourse.processing.org/u/boytedinho)\
**Post date:** [December 15, 2023, 1:52am UTC](https://discourse.processing.org/t/float-array-limitation/43469/3 "2023-12-15T01:52:59Z")

</div>

Thank you so much for the answer and tips, @mnse ! You opened my eyes for that kind of problem. Really helpful links too. Saving them.
