number format

convert number into formatted number

by Osama Qassar

JavaScript

var nFormat = function(v, _unit, _round) {
  !_unit ? _unit = '' : _unit;
  !_round ? _round = true : _round;
  if (!v) { return 0 };
  if(_round){
    if(v > 9999){ v = v.toString().substr(v.toString().length-4)+'000'; }
  }
  return Math.floor(v).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ".") + ' ' + _unit;
};

alert( nFormat(7272727) );