【发布时间】:2010-01-06 08:39:41
【问题描述】:
例如,C++ 中的 %11.2lf 在 Java 中变为 %11.2f。
长格式呢?
【问题讨论】:
标签: java string.format
例如,C++ 中的 %11.2lf 在 Java 中变为 %11.2f。
长格式呢?
【问题讨论】:
标签: java string.format
您可能已经知道,没有必要指定l 标志。根据the docs,十进制整数由d 指定,就像在C++ 中一样。所以答案就是%d。
【讨论】:
使用%d 表示小数(long、int)。它工作正常。例如:
System.err.println(String.format("%d", 193874120937489387L));
...会打印得很好。阅读java.util.Formatter了解更多详情。 %d 会占用long,没问题。
【讨论】: