accounting货币汇率(前端)
来源:互联网 发布:大数据行业做什么 编辑:程序博客网 时间:2024/06/04 19:37
官方手册
单击我看效果
手册方法
前言:可以将货币进行转换,将数值转换为货币,运算非常精确,可以设置任何一个货币符号及其他功能。
基础引入
<!-- 下面的使用百度资源库加载货币accounting.js --><script type="text/javascript" src="http://apps.bdimg.com/libs/accounting.js/0.3.2/accounting.min.js"></script>
formatMoney() 方法
一般使用
formatMoney(参数一,参数二,参数三,参数四,参数五);
// 参数一:货币值console.log(accounting.formatMoney(12345678)); // 输出结果:$12345678// 参数二: 货币的符号(默认是美金符号)console.log(accounting.formatMoney(12345678,'¥'));// 参数三:小数点后面尾数多少位(自动四舍五入帮你算好)console.log(accounting.formatMoney(12345.678,'¥',2)) // ¥12345.68// 参数四:改变分隔符号,比如满3个单位就的使用,逗号来分隔;console.log(accounting.formatMoney(12345.678,'¥',2,'▲')) // // 下面参数五:改变小数点的符号console.log(accounting.formatMoney(-12345.678,'¥',2,'▲','★')); // ¥12▲345★68
简写
看着这么多传参,太臃肿,1、如果我只要是小数点符号,改变了,还要一个一个值传进去,是不是不优化啊。2、再加上看的不直观,不能一眼就能看出传的什么东西,那么官方就提供了一个非常有效传参方式
将第二个参数用json对象方式传值
// 语法:formatMoney(参数一,{ symbol : "$", // 货币符号为$ decimal : ".", // 小数点(位数)符号为. thousand: ",", // 货币分隔符号 precision : 2, // 货币后面的小数点位数为2(就是说,精确到后面两位数) format: "%s%v" // 货币符号位置(简写)});// 参数一还是数值。
更改一些特殊需求
- 更改负数符号。
- 将货币设置位置。
- 当货币值为0时,设置字符串。
// 更改负数符号改成其他符号。accounting.formatMoney(-5318008, { symbol: "¥", precision: 0, thousand: "·", format: { neg : "%s (%v)" }});// 将货币设置位置。accounting.formatMoney(5318008, { symbol: "¥", precision: 0, thousand: "·", format: { pos : "%v %s" // 如果值为: "%s %v" 的话,则默认的在左边 } // 简写(直接可以使用),format:"%v %s"});// 当数字为0时,设置字符串accounting.formatMoney(0, { // 这里设置为0。 symbol: "¥", precision: 0, thousand: "·", format: { zero: "%s 没有钱" // 如果值为: "%s %v" 的话,则默认的在左边 } // 简写(直接可以使用),format:"%v %s"});
formatColumn()方法
formatColumn将多个数值进行一次性转换。此处还有些东西,不知道是神马??
其实参数和上面formatMoney方法 一样,也是第一个货币值,第二参数,钱的符号,等等一样。
console.log(accounting.formatColumn([123.5, 3456.49, 777888.99, 12345678, -5432], "$ ",2,'▲','★'));
// 参数一:数组类型,将多个数字放进入。console.log(accounting.formatColumn([123.5, 3456.49, 777888.99, 12345678, -5432])); // 输出结果:// 参数二:字符串类型,钱的符号(货币符号)。console.log(accounting.formatColumn([123.5, 3456.49, 777888.99, 12345678, -5432], "$ "));// 参数三:小数点后面尾数多少位(自动四舍五入帮你算好)console.log(accounting.formatColumn([123.5, 3456.49, 777888.99, 12345678, -5432], "$ ",2));// 参数四:改变分隔符号,比如满3个单位就的使用,逗号来分隔;console.log(accounting.formatColumn([123.5, 3456.49, 777888.99, 12345678, -5432], "$ ",2,'▲');// 参数五:改变小数点的符号console.log(accounting.formatColumn([123.5, 3456.49, 777888.99, 12345678, -5432], "$ ",2,'▲','★'));
formatNumber()方法
formatNumber:用于精确到小数点
==参数和上面差不多。==
// 参数一 :货币金额console.log(accounting.formatNumber(5318008));// 参数二 :精确的小数点尾数console.log(accounting.formatNumber(9876543.21, 3));// 参数三: 改变分隔符号,比如满3个单位就的使用,逗号来分隔;console.log(accounting.formatNumber(9876543.21, 3, "@");// 参数四 | 改变小数点的符号console.log(accounting.formatNumber(9876543.21, 3, "@",'★'));
toFixed()
toFixed() 将小数点进行舍入,比如四舍五入。大家都知道,满十进一的十进制,满60进一(表),对于javascript来说,运算也有不精确度的地方。
// 下面,使用原生javascript的 toFixed() 方法来运算做比较。console.log((0.615).toFixed(2)); // 0.61// 使用toFixed来计算浮点数,和上面进行比较console.log(accounting.toFixed(0.615, 2)); // 0.62
unformat()
unformat 将字符串格式格式货币,去除(删除)货币的格式,返回数字。他只认识一些常用的符号,其他的特殊符号,都是不认识的。
console.log(accounting.unformat("GBP5,318,008.00")); // 5318008console.log(accounting.unformat("$12,345,678.00")); // 12345678console.log(accounting.unformat("9@876@543★210")); // 9876543210
accounting.settings
配置一些常用的货币符号、货币的分隔符号、货币的精确等等
accounting.settings = { currency: { symbol : "$", // 配置:货币符号为$ format: "%s%v", // 配置:货币符号的位置 decimal : ".", // 配置:小数点 thousand: ",", // 配置:分隔符(货币分隔符) precision : 2 // 配置:分隔位数 }, number: { precision : 0, // 精确的数字 thousand: ",", // 分隔 decimal : "." // 小数位数尾号符号 }}
阅读全文
0 0
- accounting货币汇率(前端)
- accounting
- 获取货币汇率API
- 货币汇率转换之笔记
- SAP的财务会计架构(Financial Accounting)
- SAP的财务会计架构(Financial Accounting)
- SAP的财务会计架构(Financial Accounting)
- SAP的财务会计架构(Financial Accounting)
- SAP 平行帐(Parallel Accounting)
- Y2K Accounting Bug(简单枚举)
- Y2K Accounting Bug(poj2586,枚举)
- POJ 2586 Y2K Accounting Bug(贪心)
- poj2586 Y2K Accounting Bug(贪心)
- POJ 2586:Y2K Accounting Bug(贪心)
- POJ 2459 Feed Accounting(水~)
- POJ 2586 Y2K Accounting Bug(贪心)
- Y2K Accounting Bug(二进制+枚举)
- POJ 2586 Y2K Accounting Bug(贪心)
- Java集合框架
- 定时器中断
- java方法测试总结
- struts2_day04_01_拦截器概述_02_拦截器底层原理(aop思想)_03_拦截器底层原理(责任链模式)
- 二分查找
- accounting货币汇率(前端)
- Hibernate拦截器与事件系统
- 关于机器学习,你应该至少学习这8个落地案例|干货集锦
- 最小长度电路板排列问题
- Python读写文件模式
- 李宏毅机器学习2016 第二讲 偏差与方差
- 数据结构
- codeforce 897B
- ros安装出现依赖问题