源代码:
public static void main(String[] args){
DecimalFormat df = new DecimalFormat();
df.setMaximumFractionDigits(2);
df.setGroupingSize(0);
df.setRoundingMode(RoundingMode.FLOOR);
double commission = roundDouble((Double.parseDouble("145")*0.001),2);
System.out.println((Double.parseDouble("145")*0.001));
System.out.println(commission);
}
public static double roundDouble(double d, int dec) {
double x = d * (Math.pow(10, dec));
long v = Math.round(x);
return v / (Math.pow(10, dec));
}
预期输出结果:
0.145
0.15
实际输出:
0.145
0.14