4000.000 补发金额:2000.000
我这个数值后面多了。000,我怎么去除?
程序是直接写到jsp页面的,有没有好的方法?
String str = "2000.000";
str = str.substring(0,str.indexOf("."));
System.out.println(str);
double d = Double.parseDouble(str);
System.out.println((int)d);
BigDecimal bd = new BigDecimal(str);
NumberFormat f = NumberFormat.getInstance();
f.setMaximumFractionDigits(0);
System.out.println(f.format(bd));
有3个方法
1 使用字符串函数,比如
String str = "2000.000";
str = str.substring(0,str.indexOf("."));
2 正规一些的可以转化为数字类型,比如
BigDecimal bd = new BigDecimal("2000.000");
然后你用NumberFormat自己指定小数点的尾数
3 偷懒的方法,转化为数字
double d = Double.parseDouble("2000.000");
然后用整数输出
int num = (int)d;