这基本上就是我想要做的
// ... some code, calculations, what have you ...
long timeToAdd = returnTimeToAddInLongFormat();
// lets output the long type now, and yes i need the width and precision.
System.out.printf("Time to add: %13.10ld", timeToAdd);
我已经阅读了有关该主题的大部分 google 搜索,并认为我在概念上理解如何做到这一点,但 JRE 不断向我抛出 UnknownFormatConversionException
并告诉我我的输入大小修饰符 l
不起作用。
还有其他方法可以做到这一点,还是我错过了一些小事?
最佳答案
Java 将所有整数值视为 d
,没有 ld。甚至 byte 和 BigInteger 也是 d
类型。它还假设整数没有小数位。如果要显示 10 个零,可以先转换为 double 并使用 f
关于java - 如何使用输入大小修饰符打印长类型值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7586481/