javascript - Comma-formated numbers in jQuery -


i have following function in jquery format number comma-formatted:

function commaformattedn(amount) {      var delimiter = ",";      var = parseint(amount);      if(isnan(i)) { return ''; }      = math.abs(i);      var minus = '';     if (i < 0) { minus = '-'; }      var n = new string(i);     var = [];      while(n.length > 3)     {         var nn = n.substr(n.length-3);         a.unshift(nn);         n = n.substr(0,n.length-3);     }      if (n.length > 0) { a.unshift(n); }      n = a.join(delimiter);      amount = minus + n;      return amount;  } 

i calling function on

 $('.text_field1').bind("focus blur change keyup", function(){      var $el = $(this);     $el.val(commaformattedn($el.val())); }); 

it's working fine, problem is, when number of digits increase 5, makes nothing. digits deleted , starts again.

  1. there bug related sign. using absolute value instead of original one.
  2. your code seems work fine, can try debugging way calling function.

here working code minor edit ( sign related ) : http://jsfiddle.net/qcvdc/1/


Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -