Decimalformat ist eine konkrete Unterklasse von Numberformat, die zur Format -Dezimalzahlen verwendet wird.
Paket com.myk.hash; import java.text.decimalformat; öffentliche Klasse App {public static void main (String [] args) {// Zahlenformatierung, # und 0 sind Platzhalter, #: Wenn die Anzahl der zu formatierten Ziffern nicht ausreicht, füllt # die Blätter. 0: Wenn die Anzahl der zu formatierten Ziffern unzureichend ist, füllt 0 DecimalFormat df1 = new DecimalFormat ("#. ##"); // Zahlenformatierungssystem.out.println (df1.format (0.01)); DecimalFormat df2 = new DecimalFormat ("0,000"); // Zahlenformatierungssystem.out.println (df2.format (0,01)); // Zahlenformatierungssystem.out.println (df3.Format (0,11)); // Zahlenformatierungssystem.out.println (df3.Format (0,11)); // Zahlenformatierungssystem.out.println (df3.Format (0,11)); // Zahlenformatierung decimalformat df4 = new DecimalFormat ("#. ##%"); // Zahlenformatierungssystem.out.println (df4.format (0.01111)); // verwenden "," die Zahlen durch 3 Ziffern Dezimalformat df5 = new DecimalFormat (", ###"); // Digital Format System.out.println (df5.Format (981725025)); DecimalFormat df6 = new DecimalFormat ("Top, ###"); // digitales Formatsystem.out.println (df6.format (981725025)); DecimalFormat df7 = new DecimalFormat ("##, ###. 000"); // digitales Formatierungssystem.out.println (df7.format (981725025.981725025)); //-Änderung}}Ergebnis
0.010.01011.000%1,11%981.725.025 Top981.725.025981.725.025,982
Das obige ist der gesamte Inhalt dieses Artikels. Ich hoffe, es wird für das Lernen aller hilfreich sein und ich hoffe, jeder wird Wulin.com mehr unterstützen.