27

我有这些数字的数组

61672
8414449
264957

我使用这样的DecimalFormat对象

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

得到这些结果

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

但我需要将结果与右对齐,如下所示

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

已经感谢您的帮助。

4

1 回答 1

46

您可以将其包装成这样的String.format调用:

String.format("%15s", formatter.format(i))
于 2011-05-21T07:56:59.470 回答