accounting.formatNumber/Money的使用格式化货币、数字
2014-10-14 09:17
381 查看
之前写项目在jsp页面中一直使用jstl的<fmt>标签,但是在js/jqery使用不了。于是我又找到另外一种js插件accounting.js
首先使用accounting.js应先导入<script type="text/javascript" src="../../scripts/accounting.js"></script>
根据自己的文件位置填写src="×××/accounting.js".
然后是在使用的时候:accounting.formatMoney();accounting.formatNumber();
效果如下:
accounting.formatNumber(50000)-----50,000
accounting.formatMoney(5000)------$50,000.00
那为什么会出现这样的效果呢,这就需要查看accounting.js是怎么编写的。
首先,打开accounting.js我们会看到,如下:
lib.settings = {
currency: {
symbol : "",
// default currency symbol is '$'
//默认的货币符号
'$'
format : "%s%v",
// controls output: %s = symbol, %v = value (can be object, see docs)
//输出控制: %s = 符号, %v = 值或数字 (can be object: see below)
decimal : ".",
// decimal point separator
//小数点分隔符
thousand : ",",
// thousands separator,千位分隔符
precision : 0,
// decimal places,小数位数
grouping : 3
// digit grouping (not implemented yet),数字分组
},
number: {
precision : 0,
// default precision on numbers is 0,精度,默认的精度值为0
grouping : 3,
// digit grouping (not implemented yet),数字分组
thousand : ",",
decimal : "."
}
};
那么,这就是accounting.js要显示的样式了
如果想要更改显示样式直接在代码中这样写:
显示两位小数:accounting.formatNumber(50000,2)-------------50,000.00
显示中文货币符号:accounting.formatMoney(50000,"¥",2)-------¥50,000.00
不显示货币符号:accounting.formatMoney(50000,"",2)-----------50,000.00
ps:括号内直接传值,例如:accounting.formatMoney(gponGroups[i].baseFee,"",2),主要与<fmt>标签不同的是,可以在js/jquey中使用。
其他效果可以尝试一下,就不再写了。
首先使用accounting.js应先导入<script type="text/javascript" src="../../scripts/accounting.js"></script>
根据自己的文件位置填写src="×××/accounting.js".
然后是在使用的时候:accounting.formatMoney();accounting.formatNumber();
效果如下:
accounting.formatNumber(50000)-----50,000
accounting.formatMoney(5000)------$50,000.00
那为什么会出现这样的效果呢,这就需要查看accounting.js是怎么编写的。
首先,打开accounting.js我们会看到,如下:
lib.settings = {
currency: {
symbol : "",
// default currency symbol is '$'
//默认的货币符号
'$'
format : "%s%v",
// controls output: %s = symbol, %v = value (can be object, see docs)
//输出控制: %s = 符号, %v = 值或数字 (can be object: see below)
decimal : ".",
// decimal point separator
//小数点分隔符
thousand : ",",
// thousands separator,千位分隔符
precision : 0,
// decimal places,小数位数
grouping : 3
// digit grouping (not implemented yet),数字分组
},
number: {
precision : 0,
// default precision on numbers is 0,精度,默认的精度值为0
grouping : 3,
// digit grouping (not implemented yet),数字分组
thousand : ",",
decimal : "."
}
};
那么,这就是accounting.js要显示的样式了
如果想要更改显示样式直接在代码中这样写:
显示两位小数:accounting.formatNumber(50000,2)-------------50,000.00
显示中文货币符号:accounting.formatMoney(50000,"¥",2)-------¥50,000.00
不显示货币符号:accounting.formatMoney(50000,"",2)-----------50,000.00
ps:括号内直接传值,例如:accounting.formatMoney(gponGroups[i].baseFee,"",2),主要与<fmt>标签不同的是,可以在js/jquey中使用。
其他效果可以尝试一下,就不再写了。
相关文章推荐
- C#中格式化数字输出,使用NumberFormatInfo.NumberGroupSeparator 属性
- JSTL fmtformatNumber日期、 数字、货币格式化
- 使用NumberFormat格式化数字
- 使用NumberFormat格式化数字
- <fmt:formatNumber>标签用于格式化数字,百分比,货币。
- Java NumberFormat数字、货币值和百分数等的格式化处理
- JSTL fmtformatNumber日期、 数字、货币格式化
- 不使用number_format()函数格式化数字
- 数字格式化函数:Highcharts.numberFormat()
- JSTL之数字、日期格式化<fmt:formatNumber/>、<fmt:formatDate/>
- JSTL之数字、日期格式化<fmt:formatNumber/>、<fmt:formatDate/>
- Java常用类库——数字格式化(NumberFormat)与大数操作(BigIntger、BigDecimal类)
- DecimalFormat 是 NumberFormat 的一个具体子类,用于格式化十进制数字
- Java格式化数字错误 java.lang.NumberFormatException分析
- 使用MessageFormat格式化数字,日期
- JAVA中使用format()方法格式化数据(日期转换,货币)
- php大数字格式化,大数据格式化,科学计数法,长数字格式化,函数number_format
- php:number_format() 函数通过千位分组来格式化数字
- php中数字格式化函数number_format解析
- php number_format() 函数通过千位分组来格式化数字的实现代码