Created
April 22, 2015 01:03
-
-
Save RyoSugimoto/9a6658c758e06e95dee7 to your computer and use it in GitHub Desktop.
指定した桁数でカンマを追加する。
This file contains hidden or 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
| 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