Hey guys,
I'm trying to do the above function to format numbers in a repeater but all the numbers in the repeater are only showing the last value although the console is showing the correct values for each.
export function dataset1_ready() {
$w("#repeater1").forEachItem( ($w, itemData, index) => {
var number = Number(itemData.price);
$w("#price").text = number.toLocaleString();
kFormatter(number);
});
}
function kFormatter(number) {
if(number < 1000000 && number > 999) {
let x = Math.round(number/1000) + "k";
$w("#price").text = x;
console.log(x);
}
else if(number < 10000000 && number > 999999) {
let x = Math.round(number/1000000) + "m";
$w("#price").text = x;
console.log(x);
}
else if(number < 1000000000 && number >= 10000000) {
let x = Math.round(number/1000000) + "m";
$w("#price").text = x;
console.log(x);
}
}
Would be grateful if someone pointed out my error.
Thank you.
Hi guys,
I would like to format the number displayed in the Wix store - Filter box (like attached image).
1.000.000,00 to 1.000.000
But I don't know how to code.
Would be grateful if anyone can help?
Hi, Shan.
I haven't used the repeater but it appears that you do nothing with number after you kFormatter() it; in lieu of the following:
$w("#price").text = number.toLocaleString(); kFormatter(number);
does it work if you replace the above code with the following code:
$w("#price").text = kFormatter(number.toLocaleString());
?