js 金钱格式转化
来源:互联网 发布:淘宝教程我要自学网 编辑:程序博客网 时间:2024/05/17 06:42
Number.prototype.formatMoney = function (places, symbol, thousand, decimal) { places = !isNaN(places = Math.abs(places)) ? places : 2; symbol = symbol !== undefined ? symbol : "¥"; thousand = thousand || ","; decimal = decimal || "."; var number = this, negative = number < 0 ? "-" : "", i = parseInt(number = Math.abs(+number || 0).toFixed(places), 10) + "", j = (j = i.length) > 3 ? j % 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) : "");};
用法:
// Default usage and custom precision/symbol : var revenue = 12345678; alert(revenue.formatMoney()); // ¥12,345,678.00 alert(revenue.formatMoney(0, "HK$ ")); // HK$ 12,345,678 // European formatting: var price = 4999.99; alert(price.formatMoney(2, "€", ".", ",")); // €4.999,99 // It works for negative values, too: alert((-500000).formatMoney(0, "£ ")); // £ -500,000
转载至 http://www.cnblogs.com/mingmingruyuedlut/archive/2013/05/19/3082177.html
0 0
- js 金钱格式转化
- JS 将数字类型转化为没3个一个逗号的金钱格式
- js时间格式转化
- JS函数 金钱转换为大写格式 壹佰伍拾柒圆伍角陆分这样
- js中转化日期格式
- 【js】vue时间格式转化
- gridview里金钱格式
- 标准金钱格式
- PHP 转为金钱格式
- JS金钱转换大写
- 利用JS实现时间格式转化
- js转化毫秒为时间格式
- js字符串和json格式互相转化
- js内时间戳日期格式转化
- js时间转化为指定格式时间
- JS 将数字转化成为货币格式
- JS将String格式转化Date
- JS将数字转化为货币格式
- Android性能(时间)分析工具-TraceView的使用
- Android内存管理试验——浅谈ImageView的Bitmap的使用
- 牛顿法-最优化方法
- 毕业生-告诫自己每天看一遍,你将获益终生。
- 音视频原始数据产生器
- js 金钱格式转化
- 解决Unsupported major.minor version 51.0问题的感悟
- IDF实验室:百密一疏--笨笨的小猪
- Android从资源文件中读取文件全
- 随笔——2015.05.25
- android 多线程 - 并行包线程池为例说说线程池的设计需求及使用
- Struts2的Action接受参数的方法介绍
- openwrt 编译命令记录
- arm-linux-gdb调试工具的安装与交叉编译gdbserver