JSFiddle - React, Tailwind, and code Playground

JavaScript

function format(input) {
    var x = input.toFixed(8).split('.');
    return x[0].replace(/\B(?=(\d{3})+(?!\d))/, ',') + 
           ('.' + x[1]).replace(/\.?0+$/, '');
}

var numbers = [121, 14231.439400000, 1.123456789, -9012.4430001];
for(var i = 0; i < numbers.length; i++) {
    $("<p>").text(format(numbers[i])).appendTo("body");
}