Are you first timer at lazacode.org? Why not join us and start exchange your programming knowledge with everyone. Register today!

JS .toLocaleString() - Add comma into number

0 votes
94 views
added Jul 11 in Javascript by LC Marshal Lieutenant (14,830 points)
edited Aug 1 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 by LC Marshal Lieutenant (14,830 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.
...