开发者

how to printf a long typed value using input size modifier?

开发者 https://www.devze.com 2023-04-09 06:19 出处:网络
This is basically what I am trying to do // ... s开发者_JAVA技巧ome code, calculations, what have you ...

This is basically what I am trying to do

// ... s开发者_JAVA技巧ome 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?


Java treats all integer values as d, there is no ld. Even byte and BigInteger is a d type. It also assumes integers have no decimal places. If you want to show 10 zeros, you can convert to double first and use f

0

精彩评论

暂无评论...
验证码 换一张
取 消