最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
纯js格式化货币:currencyFmatter.js用法
时间:2016-11-05 编辑:简简单单 来源:一聚教程网
currencyFmatter.js是一款简单实用的纯js格式化货币插件。该插件包含155种不同国家的货币,以及715种不同语言的本地化设置。它还能处理某些不采用的货币,功能非常强大。
HTML
首先在页面中引入currencyFormatter.js文件。
HTML结构:
javascript
OSREC.CurrencyFormatter.formatAll(
{
selector: '.money',
currency: 'CNY'
});
看出来了吧,selector对应的选择器,currency对应的是人民币标识CNY。
通过OSREC.CurrencyFormatter.format(number, parameters)方法可以非常容易的格式一个货币数值。只需要简单的在配置参数中设置你需要的格式即可。 参数的格式如下:
var parameters =
{
currency: 'EUR', // If currency is not supplied, defaults to USD
symbol: '?#39;, // Overrides the currency's default symbol
locale: 'fr', // Overrides the currency's default locale (see supported locales)
decimal: ',', // Overrides the locale's decimal character
group: '.', // Overrides the locale's group character (thousand separator)
pattern: '#,##0.00 !' // Overrides the locale's default display pattern
// The pattern follows standard unicode currency pattern notation.
// comma = group separator, dot = decimal separator, exclamation = currency symbol
}
通常你不需要指定所有的参数。该插件会使用适当的格式来显示每一种货币和语言设置。
OSREC.CurrencyFormatter.format(2534234, { currency: 'INR' }); // Returns ? 25,34,234.00
OSREC.CurrencyFormatter.format(2534234, { currency: 'EUR' }); // Returns 2.534.234,00 ?/code>
OSREC.CurrencyFormatter.format(2534234, { currency: 'EUR', locale: 'fr' }); // Returns 2 534 234,00 ?
使用OSREC.CurrencyFormatter.formatAll(parameters)方法可以将所有包含数值的元素都转换为好看的货币格式。
-
上一个: 解决apicloud真机测试空白办法
相关文章
- HTML简单购物数量小程序代码展示 10-31
- html canvas实现弹幕功能 10-31
- HTML中空格表示的意义 10-31
- html area标签解读 10-31
- html使用表单标签实现注册页面代码展示 10-31
- 使用HTML截图并保存为本地图片的代码展示 10-31