Created
May 30, 2014 05:55
-
-
Save zfkun/337e72e5bdcd247dfaf2 to your computer and use it in GitHub Desktop.
number to money style
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
define( function ( require, exports, module ) { | |
/** | |
* 货币数字格式化 | |
* 将数字整数部分按3位分组加逗号格式化 | |
* | |
* @example | |
* ```javascript | |
* var money = 123456789.1234567; | |
* var moneyFormated = toMoney( money ); | |
* console.info( 'format from `%s` to `%s`', money, moneyFormated ); | |
* // output: format from `123456789.1234567` to `123,456,789.1234567` | |
* ``` | |
* @param {number|string} number 待格式化的数字 | |
* @return {string} 格式化后的字符串 | |
*/ | |
function toMoney ( number, group ) { | |
return number.toString().replace( /\B(?=(\d{3})+(?:\.\d+$))/g, ',' ); | |
} | |
return toMoney; | |
} ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment