Skip to content

Instantly share code, notes, and snippets.

@kiinlam
Created November 17, 2017 08:02
Show Gist options
  • Save kiinlam/14ab6bc0958ab81ef5e67c6636050367 to your computer and use it in GitHub Desktop.
Save kiinlam/14ab6bc0958ab81ef5e67c6636050367 to your computer and use it in GitHub Desktop.
数值增加千分位分隔,保留小数部分
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