JSFiddle - React, Tailwind, and code Playground

by meo

JavaScript

var formatNumber = function( n,toFixed ){
    return {
        nbr: n.toFixed(toFixed || 2),
        addCommas: function( kind ){
            var tempNbr, regexp;
            
            regexp = /(\d{1,3})(?=(\d{3})+$)/g;
            kind =  kind || "'";

            tempNbr = (this.nbr + "").split(".")[0];
            tempNbr = (tempNbr + "").replace(regexp, "$1" + kind);
            
            return tempNbr + "." + (this.nbr + "").split(".")[1];
        },
        reverse: function( nr ){
            nr = nr ? nr + "" : this.nbr; 
            return nr.split("").reverse().join("")
        }    
    };
};

console.log( formatNumber(134234424234234.45).addCommas() )