JSFiddle - React, Tailwind, and code Playground

HTML

<input type="number" id="input">
<output id="output"></output>

JavaScript

function formatNumber(num) {
            var n1, n2;
            num = num + '' || '';
            // works for integer and floating as well
            n1 = num.split('.');
            n2 = n1[1] || null;
            n1 = n1[0].replace(/(\d)(?=(\d\d)+\d$)/g, "$1,");
            num = n2 ? n1 + '.' + n2 : n1;
            return num;
        }
 var _input = $('#input');
 var _output = $('#output');
   
_input.on("change keyup", function(){
  if(this.value){
  	_output.val(formatNumber(this.value));
  }
});