Created
July 15, 2011 06:33
-
-
Save taiju/1084199 to your computer and use it in GitHub Desktop.
3桁区切りフォーマット関数
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* アルゴリズム 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