2012-02-01 6 views
5

che sto cercando di fare qualcosa di simile in java (Eclipse Indigo):Come formattare un intero su una stringa a quattro zero zero?

input - 16 (integer); 
Output - "0016" ; 

input - 201 (integer); 
Output - "0201" ; 

intput - 1716 (integer); 
Output - "1716" ; 

In VB.net ho potuto utilizzare:

dim num as integer 
dim str as string 

str = Format(num, "0000") 

Come posso fare lo stesso in java? Grazie in anticipo ...

risposta

3

vorrei anche andare per il String#format() come risposta da MRE, ma si potrebbe anche fare:

new DecimalFormat("0000").format(number); 

Date un'occhiata here per ulteriori dettagli.