Teilen Sie Daten vom Typ Long in Java, das Ergebnis behält zwei Dezimalstellen bei

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%

Guess you like

Origin blog.csdn.net/m0_37899908/article/details/131904732