JSFiddle - React, Tailwind, and code Playground

by sushanth009

HTML

<table>
    <tbody>
        <tr class="numberWithCommas">
            <td>5000</td>
            <td>5600</td>
        </tr>
         <tr class="numberWithCommas">
            <td>3784</td>
            <td>2397</td>
        </tr>
    </tbody>
</table>

CSS

td
{
    padding :5px;
}

JavaScript

function numberWithCommas(x) {
    return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
};

$('table tr.numberWithCommas').each(function(){
    var $tr = $(this);
    $tr.find('td').each(function(){
        var $td = $(this);
        $td.html(function(){
            return  numberWithCommas(this.innerHTML);
        });
    });        
});