Skip to content

Instantly share code, notes, and snippets.

@RyoSugimoto
Created April 22, 2015 01:03
Show Gist options
  • Select an option

  • Save RyoSugimoto/9a6658c758e06e95dee7 to your computer and use it in GitHub Desktop.

Select an option

Save RyoSugimoto/9a6658c758e06e95dee7 to your computer and use it in GitHub Desktop.
指定した桁数でカンマを追加する。
var addCamma = function (number, fig) {
var str, ptn;
fig = fig || 3;
str = String(number).replace(/,/g, '');
ptn = RegExp('^(-?\\d+)(\\d{' + fig + '})');
while(str != (str = str.replace(ptn, "$1,$2")));
return str;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment