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

A simple question, but I bet that the question here will probably be more direct than trying to understand the documentation for MessageFormat :

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

The observed value is "12.345".

The required value is "12345".

+82
java messageformat
Dec 21 '09 at 19:32
source share
5 answers
+40
Dec 21 '09 at 19:35
source share
 MessageFormat.format("{0,number,#}", foo); 
+228
Dec 21 '09 at 19:38
source share

As an alternative, String.format and java.util.Formatter can work for you String.format ...

-one
Dec 21 '09 at 19:39
source share

The shortest way is

 long foo = 12345; String s = ""+foo; 
-one
Jan 04 '10 at
source share

You can try:

 String s = new Long(foo).toString(); 
-5
Dec 22 '09 at 4:51
source share



All Articles