给定要给Double类型数字,四舍五入求百分数,可以保留整数 两位
0.441876900638 ==>44.19% or 44%
用拓展的方法
//截取
double num = Double.parseDouble("0.446876900638".substring(0, 7));
System.out.println( Math.round((num*1000)/10));
String numstr=Math.round(num*10000)+"";
StringBuffer sb = new StringBuffer(numstr);
//索引插入
System.out.println( sb.insert(2,"."));
45
44.69
求百分数
double mix = i / sumSales1;
BigDecimal b = new BigDecimal(mix * 100);
double f1 = b.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
因篇幅问题不能全部显示,请点此查看更多更全内容