js 将数字格式化成货币(钱)格式
2017-12-20 17:16
375 查看
// 价格,小数点后几位,替换$,千分位显示什么符号默认',' , 小数点'.' function formatMoney(number, places, symbol, thousand, decimal) { number = number || 0; places = !isNaN(places = Math.abs(places)) ? places : 2; symbol = symbol !== undefined ? symbol : "$"; thousand = thousand || ","; decimal = decimal || "."; var negative = number < 0 ? "-" : "", i = parseInt(number = Math.abs(+number || 0).toFixed(places), 10) + "", j = (a = i.length) > 3 ? a % 3 : 0; return symbol + negative + (j ? i.substr(0, j) + thousand : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + thousand) + (places ? decimal + Math.abs(number - i).toFixed(places).slice(2) : ""); } formatMoney(12345.67) // $12,345.67 formatMoney(12345.67 , 3 , "¥") // ¥12,345.670 //再把'$12,345.67' 变成纯数字 12345.67 parseFloat('$12,345.67'.replace(/[^0-9-.]/g, ''))
原文:https://www.cnblogs.com/mingmingruyuedlut/archive/2013/05/19/3082177.html
相关文章推荐
- js格式化货币,数字转货币格式。
- js数字的货币格式表示法(每三位一个逗号分隔)
- JS数字_货币格式
- js将number数值转化成为货币格式,货币格式化,金钱过滤器,货币过滤器,vue货币过滤金钱过滤全局和局部两种实现方式
- js数字货币格式互转
- js中输入数字自动货币格式化
- JS 数字格式化为金额格式 (3位一个逗号隔开)
- JS对数字进行货币格式化并且保留两位小数点,小数用0补全
- 数字格式化成货币格式 1000 格式化成1,000
- JS 将数字转化成为货币格式
- JS 将数字转化成为货币格式
- 格式化成货币数字格式
- JSTL fmt:formatNumber日期、 数字、货币格式化
- Java数字、货币格式化
- c#中格式化货币格式( 例如: 665334.05 格式化为 665,334.05)
- js 格式化时间(显示格式为:yyyy-mm-dd hh:mi:ss)
- java格式化金额 java格式数字 保留2位小数
- JS实现的4种数字千位符格式化方法分享
- JS 数字格式千分位相互转换
- js方法格式化数字,加入千分符,并可以指定小数点位数