# Nf() number format decimal places to array using for loop

**URL:** https://discourse.processing.org/t/nf-number-format-decimal-places-to-array-using-for-loop/33182
**Category:** Beginners
**Created:** [October 31, 2021, 10:59am UTC](https://discourse.processing.org/t/nf-number-format-decimal-places-to-array-using-for-loop/33182 "2021-10-31T10:59:15Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![louise00](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/louise00/32/14869_2.png) [@louise00](https://discourse.processing.org/u/louise00)
#### Post date: [October 31, 2021, 10:59am UTC](https://discourse.processing.org/t/nf-number-format-decimal-places-to-array-using-for-loop/33182/1 "2021-10-31T10:59:15Z")

</div>

I’m migrating from p5js to processing and something from p5js that works really well its just getting stuck in processing. I’m trying to:

• Define a PImage array  
• Load a set of images that are named 0.jpg ~ 11.jpg  
• Use a For Loop together with Nf() to abbreviate the loadImage command by using the [i] with the Nf() formatting to take 0 to 0000.jpg etc.

This works great in p5js. Java is not yet my friend.

Here is my code:

```auto
PImage[] frontImgs = new PImage[12];
String[] formatOurJPG;

void setup() {
  size(1024, 600);
  for(int i =0; i < 12; i++) {
    formatOurJPG[i] = (nf(i,3));
    frontImgs[i] = loadImage("front__" + formatOurJPG + ".jpg");
  }
}//end setup

```

I appreciate your help!

---

<div class="post-metadata">

### Author: ![louise00](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/louise00/32/14869_2.png) [@louise00](https://discourse.processing.org/u/louise00)
#### Post date: [October 31, 2021, 11:23am UTC](https://discourse.processing.org/t/nf-number-format-decimal-places-to-array-using-for-loop/33182/2 "2021-10-31T11:23:16Z")

</div>

Nevermind! So apparently I fixed it by changing line 2 to this:

```auto
String[] formatOurPNG = new String[12];

```

But OMGosh I seriously don’t understand the annoying syntax of array definition in Java, and why its so hard to write to arrays.

D:

---

<div class="post-metadata">

### Author: ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)
#### Post date: [October 31, 2021, 11:57am UTC](https://discourse.processing.org/t/nf-number-format-decimal-places-to-array-using-for-loop/33182/3 "2021-10-31T11:57:58Z")

</div>

Hello,

I saw another error in your code.

Test code:

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/d/d8a22eb961e2c9d90597a3d07bf1cb6dc9f6b99a.png)

Did it work as is with your correction?

`:)`

---

<div class="post-metadata">

### Author: ![louise00](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/louise00/32/14869_2.png) [@louise00](https://discourse.processing.org/u/louise00)
#### Post date: [November 1, 2021, 1:29pm UTC](https://discourse.processing.org/t/nf-number-format-decimal-places-to-array-using-for-loop/33182/4 "2021-11-01T13:29:20Z")

</div>

Hello @glv thanks for your post. What error did you see? Do you mean it’s called png in the reply and jpg in the OP? Or that the nf is set to 3 digits but I mentioned 4 in the OP?  
I corrected for both of those but if you have another error let me know!

---

<div class="post-metadata">

### Author: ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)
#### Post date: [November 1, 2021, 6:36pm UTC](https://discourse.processing.org/t/nf-number-format-decimal-places-to-array-using-for-loop/33182/5 "2021-11-01T18:36:05Z")

</div>

Hello

The loop should have:

`formatOurJPG[i]`

`:)`
