How do I format a long integer as a string without separator in Java?

Daniel Fortunov picture Daniel Fortunov · Dec 21, 2009 · Viewed 55k times · Source

Simple question, but I'll bet that asking on here will probably be more straight forward than trying to understand the documentation for MessageFormat:

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

Observed value is "12,345".

Desired value is "12345".

Answer

Daniel Fortunov picture Daniel Fortunov · Dec 21, 2009
MessageFormat.format("{0,number,#}", foo);