The first one formats a number with a thousand separator. A comma is used as a thousands separator.
function format(obj){
  var str = obj.toString();
  var re=/(-?\d+)(\d{3})/;
  while(re.test(str)){
   str=str.replace(re,'$1,$2')
  }
  return str;
}
This one removes formatting:
function deformat(str){
 var re = /,/g;
   return str.replace(re,'');
}
 
 
 Posts
Posts
 
 
No comments:
Post a Comment