Need Code HELP! Number Format in REPEATER 1K instead of 1.000, 1M instead of 1.000.000

Hi everyone
I have Collection #dataset7
i use repeater to show Collection, in each item has #price1 to show product Price
and and want that NUMBER FORMAT IN REPEATER
1K instead of 1.000
1M instead of 1.000.000
Thank you any help

Is the price stored as field type: number?
So you can do something like:

$w.onReady(() => {
    $w("#repeater1").onItemReady(($i, iData, inx) => {
    let itemPrice;
    let storedPrice = iData.price;
    if (storedPrice   >= 1000 && storedPrice  < 1000000){
        itemPrice = `${storedPrice / 1000}K`;
    } else if (storedPrice   >= 1000000) {
        itemPrice = `${storedPrice / 1000000}M`;
    } else {
        itemPrice = storedPrice.toString();
    }
        $i("#price1").text = itemPrice;
    })
})

thank you, because take time to help me, but i have tried your code, it didn’t work

i don’t know what is missing

@gongoldgoal We need more information in order to provide assistance. Please post your code and explain what you are trying to do, and what is happening.

hi @yisrael-wix , i tried J.D code below:
$w.onReady(() => {
$w(“#repeater1”).onItemReady(($i, iData, inx) => {
let itemPrice;
let storedPrice = iData.price;
if (storedPrice >= 1000 && storedPrice < 1000000){
itemPrice = ${storedPrice / 1000}K;
} else if (storedPrice >= 1000000) {
itemPrice = ${storedPrice / 1000000}M;
} else {
itemPrice = storedPrice.toString();
}
$i(“#price1”).text = itemPrice;
})
})
But it won’t work
I have Collection #dataset7
i use repeater to show Collection, in each item has #price1 to show product Price (column name is price and setting as number)
and and want that NUMBER FORMAT IN REPEATER
1K instead of 1,000
1M instead of 1,000,000

@gongoldgoal make sure that the field key in your collection is ‘price’ (or change the code in accordance). and make sure every item has a price value or add a condition to handle the undefined prices. + check that the price field is of type: number

@jonatandor35 i tried as your assistance, but nothing happen

@gongoldgoal I don’t know. Maybe someone else…
By the way, since you want to assign the text value using code, you don’t have to #price1 to the dataset (but that’s not the reason for the issue).

@gongoldgoal
If you can’t get the example from J.D. to work for you then have a look at this other recent post.
https://www.wix.com/corvid/forum/community-discussion/adding-commas-to-number-code-not-working-under-pagination

@gongoldgoal
Also, looking at the code example from J.D. and then looking at your dataset picture…

Are you actually using the ‘Price’ field in your dataset that J.D. refers to in the code sample, as your ‘Price’ field does look very empty.

This would explain why you are getting an error if you have no value in this field for the code to read from.

It does actually look like you are using the field to the left of the ‘Price’ field and therefore either need to change the code sample to the correct field or simply put the price in the ‘Price’ field as the code expects it to be.

Exactly as J.D. mentioned to you in his reply to you…
make sure that the field key in your collection is ‘price’ (or change the code in accordance). and make sure every item has a price value or add a condition to handle the undefined prices. + check that the price field is of type: number

i’m sure price field is not empty , it is behide the panel,

@gongoldgoal the code should work, and the problem is probably somewhere else.
Anyway you can try - instead of:

let storedPrice = iData.price;

To use:

let storedPrice = Number($i("#price1").text);

(assuming you connected this text element to your collection via the editor).