站内搜索: 请输入搜索关键词

当前页面: 开发资料首页JSP 专题我想将货币类型数据进行格式化?

我想将货币类型数据进行格式化?

摘要: 我想将货币类型数据进行格式化?


我想将货币类型数据进行格式化,如字符串为97.5000,我想把这个字符串格式化成为97.50,我该怎么做?

注意:这里的97.5000只是举例,还可能是101.4500(当然格式化成101.45),2345.3400(格式化成2345.34).


//scale:要保留的小数位数
public static double round(double v, int scale) {
if (scale < 0) {
throw new IllegalArgumentException(
"The scale must be a positive integer or zero");
}
BigDecimal b = new BigDecimal(Double.toString(v));
BigDecimal one = new BigDecimal("1");
return b.divide(one, scale, BigDecimal.ROUND_HALF_UP).doubleValue();
}


DecimalFormat df = new DecimalFormat("¥#,##0.00");
System.out.println(df.format(12233.1));


to rlqiang(不留):
现在怎么保留的是一位小数?


谢谢楼上的两位,都可以的.


↑返回目录
前一篇: 有关request.getSession参数(true或者false)的含义
后一篇: 怎样将数据库的字段值进行格式化?