# Issues with my Number formatting code in a repeater

**URL:** <https://forum.wixstudio.com/t/issues-with-my-number-formatting-code-in-a-repeater/30646>\
**Category:** Ask the community\
**Tags:** code, question\
**Created:** [March 23, 2020, 2:47pm UTC](https://forum.wixstudio.com/t/issues-with-my-number-formatting-code-in-a-repeater/30646 "2020-03-23T14:47:34Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![josef](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/josef/32/16612_2.png) [@josef](https://forum.wixstudio.com/u/josef)\
**Post date:** [March 23, 2020, 2:47pm UTC](https://forum.wixstudio.com/t/issues-with-my-number-formatting-code-in-a-repeater/30646/1 "2020-03-23T14:47:34Z")

</div>

Hello,  
As the title suggests I have an issue with my number formatting code in my repeaters.  
For some reason the formatting is interrupted and not executed every now and then… It happens when for example a filter is set or when you click the reset button. The very odd thing is that sometimes the formatting is applied only on some items and not on others.  
See the screenshot below to better understand what I mean.

Please note that the price of the item to the left is not formatted but the item to the right is formatted correctly.

Here is the code I use right now:

```javascript
$w.onReady(() => {
    $w("#bilarDataset").onReady(() => {
        $w('#carProductList').forEachItem( ($w, itemData, index) => {
        const numberWithCommas = (x) => {
        return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ".");
        }
    $w('#text68').text = numberWithCommas(parseInt($w('#text68').text)) + " kr";
        } );
    });
});

```

Any ideas to why this happens and what I should change in my code?

Many thanks in advance!  
/Joe

---

<div class="post-metadata">

**Author:** ![yisrael-wix](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/yisrael-wix/32/1107_2.png) [@yisrael-wix](https://forum.wixstudio.com/u/yisrael-wix)\
**Post date:** [March 23, 2020, 4:04pm UTC](https://forum.wixstudio.com/t/issues-with-my-number-formatting-code-in-a-repeater/30646/2 "2020-03-23T16:04:31Z")

</div>

You are using the [global scope selector](https://www.wix.com/corvid/reference/$w.Repeater.html#global-scope) $w in the forEachItem() function. You should be using the [repeated item scope selector](https://www.wix.com/corvid/reference/$w.Repeater.html#repeated-item-scope) $item as the documentation states.

---

<div class="post-metadata">

**Author:** ![josef](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/josef/32/16612_2.png) [@josef](https://forum.wixstudio.com/u/josef)\
**Post date:** [March 23, 2020, 6:02pm UTC](https://forum.wixstudio.com/t/issues-with-my-number-formatting-code-in-a-repeater/30646/3 "2020-03-23T18:02:04Z")

</div>

Thanks for your reply.

I changed my code to this:

```javascript
$w.onReady(() => {
    $w("#bilarDataset").onReady(() => {
        $w('#carProductList').forEachItem( ($item, itemData, index) => {
        const numberWithCommas = (x) => {
        return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ".");
        }
    $item('#saljpris1').text = numberWithCommas(parseInt($item('#saljpris1').text))+" kr";
        } );
    });
});

```

However, the problem still occurs I’m afraid. Did I miss something?

 ![](https://us1.discourse-cdn.com/wix/original/3X/c/0/c03cb981c62529b2c276c056ba2b1bafd2c6cd3a.jpeg)

As you can see the second and last item format accordingly but all the other items don’t for some reason… Any ideas?

Many thanks in advance!

---

<div class="post-metadata">

**Author:** ![josef](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/josef/32/16612_2.png) [@josef](https://forum.wixstudio.com/u/josef)\
**Post date:** [March 23, 2020, 9:01pm UTC](https://forum.wixstudio.com/t/issues-with-my-number-formatting-code-in-a-repeater/30646/4 "2020-03-23T21:01:49Z")

</div>

I fixed it. Needed to set the repeater to onItemReady instead of forEachItem.

Many Thanks for your help Yisrael!
