/**
* @param a 被除数
* @param b 除数
* @param decimalNumber 保留的小数点位数
* @return quotient 商
*/
public static String getQuotient(int a, int b, int decimalNumber) {
String quotient = null;
String str = "#.";
for (int i = 0; i < decimalNumber; i++) {
str += "0";
}
DecimalFormat format = new DecimalFormat(str);//如保留两位小数点,"#.00"
try {
double x = (double) a;
double y = (double) b;
quotient = format.format(y);
if (quotient.startsWith(".")) {
quotient = "0" + quotient;
}
System.out.println("quotient = " + quotient);
} catch (Exception e) {
e.printStackTrace();
}
return quotient;
}