29

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

1 Answer 1

52

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

String.format("%15s", formatter.format(i))
Sign up to request clarification or add additional context in comments.

1 Comment

@David The OP defined that object.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.