java String.format: numbers with localization

僤鯓⒐⒋嵵緔 提交于 2019-12-03 23:33:41

From the documentation, you have to:

  • supply a locale (as you are doing in your example)
  • include the ',' flag to show locale-specific grouping separators

So your example would become:

String.format(Locale.GERMAN, "%,d", 1234567890) 

Note the additional ',' flag before the 'd'.

An alternative to String.format() is to use MessageFormat:

MessageFormat format = new MessageFormat("The number is {0, number}", Locale.GERMAN);
String s = format.format(new Object[] {number});
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!