|
|||||||
|
|
|
![]() |
|
|
Strumenti |
|
|
#1 |
|
Registered User
Iscritto dal: Aug 2006
Messaggi: 305
|
[JAVA] convertire int in stringa a 2 cifre
Domanda semplice
Il problema è che se faccio int n1 = 2; int n2 = 11; String s1 = "" + n1; String s2 = "" + n2; allora s1 == "2" e s2 == "11" ma io vorrei che s1 fosse "02" e s2 == "11" |
|
|
|
|
|
#2 |
|
Member
Iscritto dal: Apr 2006
Messaggi: 225
|
Provato con la classe NumberFormat?
|
|
|
|
|
|
#3 |
|
Senior Member
Iscritto dal: Jul 2006
Città: Bergamo
Messaggi: 401
|
Codice:
int n1 = 2; int n2 = 11; String s1 = "" + n1; String s2 = "" + n2; s1 = s1.length() < 2 ? "0" + s1 : s1; s2 = s2.length() < 2 ? "0" + s2 : s2;
__________________
iMac 27" 5K |
|
|
|
|
| Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 00:50.



















