调用 Long 类型的 doubleValue() 方法,以及 String.format() 方法即可
public class LongFormatPercent {
public static void main(String[] args) {
Long a = 5L;
Long b = 15L;
String percentFormat = String.format("%.2f", ((a.doubleValue() / b.doubleValue()) * 100)) + "%";
System.out.println(percentFormat);
}
}
运行结果如下:
33.33%