Rufen Sie einfach die Methode doubleValue() vom Typ Long und die Methode String.format() auf
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);
}
}
Die Laufergebnisse sind wie folgt:
33.33%