Format Number with Thousand markers

JavaScript

var numero = 1000.58;

function formatThousands(n, dp) {
  n = (''+n).split('.');
  i = n[0];
  d = !(n[1]) ? '00' : n[1];
  n = i.match(/.{4}/g).join('.');
  return n + ',' + d;
}

alert(formatThousands(numero,2));

/// http://jsperf.com/compare-two-format-thousands