JSFiddle - React, Tailwind, and code Playground
by Anand Chowdhary
HTML
<h1>
User count: <span class="user-count">0</span>
</h1>
<h1>
Rounded user count: <span class="user-count-rounded">0</span>
</h1>
Babel + JSX
const userCount = 234567;
const roundIt = n => {
const numberLength = Math.ceil(Math.log10(n + 1));
const decrease = n > 100 ? 2 : 1;
return Math.floor(n / Math.pow(10, numberLength - decrease)) * Math.pow(10, numberLength - decrease);
};
// Display user count
document.querySelector(".user-count").innerHTML = userCount;
// Display rounded count
document.querySelector(".user-count-rounded").innerHTML = roundIt(userCount);