Link to home
Start Free TrialLog in
Avatar of digitalwise
digitalwise

asked on

Comma Formatted Javascript

I have some javascript that comma-formats number inputs.  Works great unless the number is a negative, and then it is adding a commas between the - sign and the first number.    My changes haven't made a difference.   Any ideas what I need to add?

function formatNumber(num) {
  num = rev(num);
  num = num.replace(/(\d{3})/g, '$1,');
  num = rev(num);
  if(num.charAt(0) == ',') num = num.substr(1);
  return num;
}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of kaufmed
kaufmed
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial