简体   繁体   中英

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:

在此输入图像描述

这是因为字体(因为字符宽度不同)将字体更改为等宽字体,问题将得到解决(我建议使用Consolas字体)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM