2017年8月17日 | Leave a comment 问题: String ret = "[" + (isBuy ? "买" : "卖") + "] " + object + " " + quantity+ " * " + priceCurrency + " " + price ; 1 String ret = "[" + (isBuy ? "买" : "卖") + "] " + object + " " + quantity+ " * " + priceCurrency + " " + price ; 如果有多条ret print 的话价格之类的不会对齐, 加 \t 也不一定对齐,对齐后会更好看 解决: 使用 format 中的width %1$15f String ret = String.format(“[ %1$s ] %2$s %5$15.6f / %3$s %4$10.2f”, new Object[]{(isBuy ? “买” : “卖”), object, priceCurrency, price, quantity}); 参考: http://docs.oracle.com/javase/8/docs/api/java/util/Formatter.html#syntax