I’m aggregating data from my collection “Scraper Final” - containing a list of sold cars.
I’m then running a calculation to find the average sold price of each car model since 2016.
The Challenge: How can I format the “Avg Price” so that data is shown as £1,598 rather than 1597.832299 for example. I’ve used Math.round before but no luck this time
Thank you!
import wixData from 'wix-data';
$w.onReady(function () {
$w("#table1").columns = [{
"id": "col1",
"dataPath": "make",
"label": "Make",
"type": "string"
},
{
"id": "col2",
"dataPath": "model",
"label": "Model",
"visible": true,
"type": "string"
},
{
"id": "col3",
"dataPath": "priceGbpNumberAvg",
"label": "Avg Price",
"visible": true,
"type": "number"
}
];
})
// Average Price Calculation 2016
let avgPriceFilter2016 = wixData.filter()
.ge("auction_date_short", "2016")
.ne("priceGbpNumber", 0)
wixData.aggregate("ScraperFinal")
.ascending("make")
.ascending("model")
.filter(avgPriceFilter2016)
.group("make", "model")
.avg("priceGbpNumber")
.run()
.then((results) => {
let items = results.items; // see below
let numItems = results.length; // 6
let hasNext = results.hasNext(); // false
$w('#table1').rows = items;
})
.catch((error) => {
let errorMsg = error.message;
let code = error.code;
});