JS .toLocaleString() - Add comma into number

0 votes
478 views
added Jul 11, 2018 in Javascript by LC Marshal Captain (25,790 points)
edited Aug 1, 2018 by LC Marshal
//Add the .toLocaleString() function next to value
console.log('5 year with/out dividend = ' + (Math.round(annual * 5 + e5)).toLocaleString() + '|' + (Math.round(annual * 5)).toLocaleString());
//e.g output 550467 to 550,467

1 Response

0 votes
responded Jul 18, 2018 by LC Marshal Captain (25,790 points)
//Dividend minus Initial amount
let x = 1.07, // 7% dividend
    annualDividend = 200000 * x, 
    initAmount = 200000,
    div1 = annualDividend, 
    div2 = div1 * x;
    
console.log('RM ' + (div2 - initAmount).toLocaleString());
lazacode.org - Malaysia's programming knowledge sharing platform, where everyone can share their finding as reference to others.
...