# How can you store floats in an array?

**URL:** <https://discourse.processing.org/t/how-can-you-store-floats-in-an-array/4184>\
**Category:** Beginners\
**Created:** [October 6, 2018, 11:38am UTC](https://discourse.processing.org/t/how-can-you-store-floats-in-an-array/4184 "2018-10-06T11:38:05Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ProsExplorer](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/prosexplorer/32/1649_2.png) [@ProsExplorer](https://discourse.processing.org/u/ProsExplorer)\
**Post date:** [October 6, 2018, 11:38am UTC](https://discourse.processing.org/t/how-can-you-store-floats-in-an-array/4184/1 "2018-10-06T11:38:05Z")

</div>

I’m trying to store float values in an array but it’s insisting that they must be stored as ‘int’.  
I need to have the fractional parts utilized so even though I could convert the floats with int(float) it’s not what I’m looking for as the solution.

How can you store floats in such an array?

```auto
float dimx=800;
float dimy=850;
float[] exposure = new float[dimx*dimy]

```

returns error:  
Type mismatch, “float” does not match with “int”

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [October 6, 2018, 12:16pm UTC](https://discourse.processing.org/t/how-can-you-store-floats-in-an-array/4184/2 "2018-10-06T12:16:35Z")

</div>

```java
static final int ROWS = 850, COLS = 800, GRID = ROWS * COLS;
final float[] exposures = new float[GRID];

void setup() {
  println(exposures.length); // 680000
  exit();
}

```

---

<div class="post-metadata">

**Author:** ![jb4x](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jb4x/32/789_2.png) [@jb4x](https://discourse.processing.org/u/jb4x)\
**Post date:** [October 6, 2018, 2:04pm UTC](https://discourse.processing.org/t/how-can-you-store-floats-in-an-array/4184/3 "2018-10-06T14:04:19Z")

</div>

Hi ProsExplorer,

the reason why you get an error is because the compiler prevents you to do something like this:

```auto
float[] exposure = new float[25.4];

```

You can’t do that and if `dimx` and `dimy` are float number, nothing can stop you from doing something like the line above.

---

<div class="post-metadata">

**Author:** ![ProsExplorer](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/prosexplorer/32/1649_2.png) [@ProsExplorer](https://discourse.processing.org/u/ProsExplorer)\
**Post date:** [October 6, 2018, 5:58pm UTC](https://discourse.processing.org/t/how-can-you-store-floats-in-an-array/4184/4 "2018-10-06T17:58:25Z")

</div>

jb4x,  
Thanks for letting me know.

Is there any other way to create an array that would store float or double numbers?

---

<div class="post-metadata">

**Author:** ![jb4x](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jb4x/32/789_2.png) [@jb4x](https://discourse.processing.org/u/jb4x)\
**Post date:** [October 6, 2018, 6:06pm UTC](https://discourse.processing.org/t/how-can-you-store-floats-in-an-array/4184/5 "2018-10-06T18:06:06Z")

</div>

You are messing up the different elements. Let’s break it down:

- `float[]` means that you want an array of float
- `exposure` is the name of the array
- `new float[n]` create an array of float containing n elements.

So you can store int, float, boolean, PVector… Anything your want.

The thing you can’t do is having n being a non integer because it makes no sense to have 2.46 elements in your array for example. Only integer values works here.

For example:

```auto
int[] intArray = new intArray[10] // create an array called intArray containing 10 integer values
float[] floatArray = new float[27] // create an array called floatArray containing 27 float values
PVector[] vectArray = new PVector[167] // create an array called vectArray containing 167 PVector

int[] intArray2 = new int[13.856] // will throw an error because 13.856 is not an integer
int[] intArray3 = new int[-56] // will throw an error because -56 is negative

```
