该方法可获取并返回对应的百分比数。
private String getPercent(int percent, int total) throws Exception { // 创建一个数值格式化对象 NumberFormat numberFormat = NumberFormat.getInstance(); // 设置精确到小数点后2位 numberFormat.setMaximumFractionDigits(2); //计算x年x月的成功率 String result = numberFormat.format((float) percent / (float) total * 100); return result+"%"; }