var val='12312.235423'
var rex = /\d{1,3}(?=(\d{3})+$)/g
val.replace(/^(-?)(\d+)((\.\d+)?)$/, function (s, s1, s2, s3) {
return '$' + s1 + s2.replace(rex, '$&,') + s3
})
//"$12,312.235423"
var val='12312.235423'
var rex = /\d{1,3}(?=(\d{3})+$)/g
val.replace(/^(-?)(\d+)((\.\d+)?)$/, function (s, s1, s2, s3) {
return '$' + s1 + s2.replace(rex, '$&,') + s3
})
//"$12,312.235423"
本文标题:使用正则表达式格式化金额
本文链接:https://www.haomeiwen.com/subject/jyyezctx.html
网友评论