Created
November 17, 2017 08:02
-
-
Save kiinlam/14ab6bc0958ab81ef5e67c6636050367 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
function thousandfy(value) { | |
let re = /\d{1,3}(?=(\d{3})+$)/g; | |
return String(value).replace(/^(\d+)((\.\d+)?)$/, (s, s1, s2) => s1.replace(re, "$&,") + s2) | |
} | |
thousandfy('24426295.93') // => 24,426,295.93 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment