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

余生长醉 提交于 2019-11-28 16:33:59

问题


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".


回答1:


Just use Long.toString(long foo)




回答2:


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



回答3:


The shortest way is

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



回答4:


As an alternative String.format and java.util.Formatter might work for you as well...




回答5:


You could try:

String s = new Long(foo).toString();


来源:https://stackoverflow.com/questions/1942118/how-do-i-format-a-long-integer-as-a-string-without-separator-in-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!