? Java ?,???? String.format()
??? DecimalFormat
??????????????????:
- ??
String.format()
??:
public class FormatInteger { public static void main(String[] args) { int number = 12345; String formattedNumber = String.format("d", number); // ?? "00012" System.out.println("Formatted integer: " + formattedNumber); } }
??????,d
????????,???????? 5 ??????,?????? 0 ???
- ??
DecimalFormat
?:
import java.text.DecimalFormat; public class FormatInteger { public static void main(String[] args) { int number = 12345; DecimalFormat decimalFormat = new DecimalFormat("00000"); String formattedNumber = decimalFormat.format(number); // ?? "00012" System.out.println("Formatted integer: " + formattedNumber); } }
??????,??????? DecimalFormat
??,?????????? "00000",???????? 5 ??????,?????? 0 ??????? format()
?????????????