My code in Javascript involves manipulating several variables and displaying a few of them in counters on-screen. Because of the math I'm using, I'll end up with numbers such as 1842.47167... or something similar. I want to display the number as 1,843 (rounded and with the "thousands" comma added). Does anyone have a simple and easy way to do it? See below for code I've tried.
console.log(coins) //Output: 1842.4716796875
commaCoins = coins;
commaCoins = Math.round(coins);
commaCoins = coins.toLocaleString();
console.log(commaCoins) //Output: "1,842.472"
//Desired result: 1,843
Anyone have a better way to do this?