public static String percent(int x, int y) {
if (x == 0 || y == 0) {
return "0";
}
double d1 = x * 1.0;
double d2 = y * 1.0;
NumberFormat percentInstance = NumberFormat.getPercentInstance();
// 设置保留几位小数
percentInstance.setMinimumFractionDigits(0);
return percentInstance.format(d1 / d2).replace("%", "");
}
网友评论