直接上代码
//import java.text.NumberFormat;
public static void main(String[] args) {
Integer a = 8;
Integer b = 80;
NumberFormat numberformat=NumberFormat.getInstance();
numberformat.setMaximumFractionDigits(2);
String result1=numberformat.format((float)a/(float)b*100);
System.out.println(result1+"%");
java.text.DecimalFormat df=new java.text.DecimalFormat("##.##%");//传入格式模板
String result2=df.format((float)a/(float)b);
System.out.println(result2);
}
效果如下: