Come faccio a formattare un intero lungo come una stringa senza separatori in Java?

StackOverflow https://stackoverflow.com/questions/1942118

  •  20-09-2019
  •  | 
  •  

Domanda

Domanda semplice, ma scommetto che chiedere qui sarà probabilmente più semplice che cercare di capire la documentazione per MessageFormat:

long foo = 12345;
String s = MessageFormat.format("{0}", foo);

valore osservato è "12.345".

valore desiderato "12345".

È stato utile?

Soluzione

Altri suggerimenti

MessageFormat.format("{0,number,#}", foo);

La via più breve è

long foo = 12345;
String s = ""+foo;

Come String.format alternativa e java.util.Formatter potrebbero funzionare per voi pure ...

Si potrebbe provare:

String s = new Long(foo).toString();
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top