anthony
anthony

Reputation: 7733

Java: String padding failed

I want to align the number on the string like that:

3 x  89 kg
3 x 133 kg

I use this format:

String.format("%1$3d x %2$3d kg", nb, weight);

But the result is not correct:

enter image description here

Upvotes: 4

Views: 62

Answers (1)

shan1024
shan1024

Reputation: 1399

This happens due to the font(because the characters don't have the same width) Change the font to a monospaced font and the problem will be solved(I recommend Consolas font for this)

Upvotes: 1

Related Questions