如何使用输入大小修饰符打印长类型值?
这基本上就是我想要做的,
// ... 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);
我已经阅读了围绕该主题的大部分谷歌搜索,并认为我理解如何从概念上做到这一点,但 JRE 不断向我抛出一个 UnknownFormatConversionException
并告诉我我的输入大小修饰符 l
不起作用。
还有其他方法可以做到这一点,还是我错过了一些小事情?
This is basically what I am trying to do
// ... 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);
I've read most of the google searches around the topic and think I understand how to do it conceptually, but the JRE keeps throwing me a UnknownFormatConversionException
and telling me my input size modifier l
doesnt work.
Is there another way to do this, or did I miss something small?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Java将所有整数值视为
d
,没有ld。甚至 byte 和 BigInteger 也是 d 类型。它还假设整数没有小数位。如果要显示 10 个零,可以先转换为 double 并使用f
Java treats all integer values as
d
, there is no ld. Even byte and BigInteger is ad
type. It also assumes integers have no decimal places. If you want to show 10 zeros, you can convert to double first and usef