Is that any elegant way to convert json response into comma separated number (for showing currency purpose).
This is what I have so far:
let data = {
"business":{
"trasactionTableData":[
{
"Date":"2019-08-19T00:00:00",
"Item Details":"Plastic - Grade A",
"slotShare":"30",
"assetBeforeonMarket":"24.000000",
"profitAfterSales":"0.000000",
"actualProfit":"22",
"actualAmount":"USD 10.00"
},
{
"Date":"2019-08-19T00:00:00",
"Item Details":"Cashless for Cash",
"slotShare":"32",
"assetBeforeonMarket":"60.000000",
"profitAfterSales":"60.000000",
"actualProfit":"0",
"actualAmount":"USD 7400.10"
},
{
"Date":"2019-08-19T00:00:00",
"Item Details":"Cashless for Cash",
"slotShare":"33",
"assetBeforeonMarket":"81.000000",
"profitAfterSales":"81.000000",
"actualProfit":"0",
"actualAmount":"USD 200.59"
}
],
}
}
for (let i = 0; i < data.trasactionTableData.length; i++) {
let slotShare = this.eosTblData[i].slotShare;
let actualAmount = this.eosTblData[i].actualAmount;
/*
// need to convert below as well
let assetBeforeonMarket = this.eosTblData[i].assetBeforeonMarket;
let profitAfterSales = this.eosTblData[i].profitAfterSales;*/
console.log('before convert', slotShare, 'After convert', String(slotShare).replace(/(.)(?=(\d{3})+$)/g,'$1,'));
}
but what I'm getting is before convert 24.000000 After convert 24.,000,000
Expected result for this example:
566,556,00
How to approach this in elegant way to achieve this conversion?