百分百源码网-让建站变得如此简单! 登录 注册 签到领金币!

主页 | 如何升级VIP | TAG标签

当前位置: 主页>网站教程>JS教程> 纯js格式化货币:currencyFmatter.js用法
分享文章到:

纯js格式化货币:currencyFmatter.js用法

发布时间:01/15 来源: 浏览: 关键词:
我们下文来为各位介绍一篇关于纯js格式化货币:currencyFmatter.js用法,希望此文章可以对各位带来一些帮助.

currencyFmatter.js是一款简单实用的纯js格式化货币插件。该插件包含155种不同国家的货币,以及715种不同语言的本地化设置。它还能处理某些不采用的货币,功能非常强大。

HTML

首先在页面中引入currencyFormatter.js文件。

<script src='currencyFormatter.js'></script>
HTML结构:

<div class='money'> 1234536.32 </div>
<div class='money'> 8798458.11 </div>
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)方法可以将所有包含数值的元素都转换为好看的货币格式。

打赏

打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,你说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

百分百源码网 建议打赏1~10元,土豪随意,感谢您的阅读!

共有7人阅读,期待你的评论!发表评论
昵称: 网址: 验证码: 点击我更换图片
最新评论

本文标签

广告赞助

能出一分力是一分吧!

订阅获得更多模板

本文标签

广告赞助

订阅获得更多模板