Skip to content

Instantly share code, notes, and snippets.

@taiju
Created July 15, 2011 06:33
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save taiju/1084199 to your computer and use it in GitHub Desktop.
3桁区切りフォーマット関数
/**
* アルゴリズム by Perlクックブック
* http://www.amazon.co.jp/Perlクックブック〈VOLUME1〉-トム-クリスチャンセン/dp/4873112028/
**/
var num = 1000000000000000000;
function commify(num, sep) {
return Array.prototype.slice.call(
Array.prototype.slice.call(num + '')
.reverse()
.join('')
.replace(/(\d\d\d)(?=\d)(?!\d\.)/g, "$1" + (sep ? sep : ','))
).reverse().join('');
}
commify(num, '_');
commify(num);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment