用DecimalFormat能不能直接把123.456格式化成123:45
小数第三未不进行四舍无入
小数第三未不进行四舍无入
解决方案 »
- 关于重写JComboBoxb界面的,如何做出如下类似效果?
- 提问:long MAX_UPON = 10000000000; 这语有错误吗?
- ----------------------------------递归问题求解!谢谢
- template 的问题
- 一个String的大小大于10M,会否出现问题?
- 大吓:怎么打开[Borland.Jbuilder.2005.企业版]?在线等?急
- 高分求思路,希望有人能回答
- 初学Java的困惑:
- 这是为什么????总得到NULL
- 我为什么不能安装j2sdk-1_4_0-win
- Config.class.getResource(".").getPath()老是报错
- 小弟很菜,希望得到大侠相助,谢谢
用下列方法可不四舍五入:
public static String format(double num, int precision){
String fN = "" + num;
int index = fN.indexOf("."); int len = fN.length();
for (int i = index + precision; i >= len; i--){
fN = fN + "0";
}
return fN.substring(0, index + precision + 1);
}
//import java.text.*;//如果不是double可先由String转换成double
public static String decimalFormat(double data)
{
Double db=Double.valueOf(String.valueOf(data*100));
NumberFormat format=new DecimalFormat("###,###.##");
format.setMinimumFractionDigits(2);
String result=format.format((db.intValue()/100d));
result=result.replace('.',':');
System.out.println(data+" after format is : "+result);
return result;
}