public class Test {
public static void main(String[] args) {
/* double i=2, j=2.1, k=2.5, m=2.9510;
System.out.println("舍掉小数取整:Math.floor(2)=" + (double)Math.floor(i));
System.out.println("舍掉小数取整:Math.floor(2.1)=" + (double)Math.floor(j));
System.out.println("舍掉小数取整:Math.floor(2.5)=" + (double)Math.floor(k));
System.out.println("舍掉小数取整:Math.floor(2.9)=" + (double)Math.floor(m)); */
Test test=new Test();
System.out.println(test.getRound(102.2357812945));
}
public double getRound(double dSource){
double iRound;
//BigDecimal的构造函数参数类型是double
BigDecimal deSource = new BigDecimal(dSource);
//deSource.setScale(0,BigDecimal.ROUND_HALF_UP) 返回值类型 BigDecimal
//intValue() 方法将BigDecimal转化为int
iRound= deSource.setScale(2,BigDecimal.ROUND_HALF_UP).doubleValue();
return iRound;
}
}