Java string align to right

喜夏-厌秋 提交于 2019-11-26 21:09:04

问题


I have an array of these numbers

61672
8414449
264957

I use a DecimalFormat object like this

DecimalFormat formatter = new DecimalFormat("###,### bytes");

to get these results

61,672 bytes
8,414,449 bytes
264,957 bytes

but I need the results to be aligned to right like the following

   61,672 bytes
8,414,449 bytes
  264,957 bytes

Your help is already appreciated.


回答1:


You can wrap it into a String.format call like this:

String.format("%15s", formatter.format(i))


来源:https://stackoverflow.com/questions/6080390/java-string-align-to-right

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