Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Printf() : Variable precision field for a double

807580Jan 13 2010 — edited Jan 13 2010
Hello,

First of all, thank you for reading my post and trying to help me, I really appreciate it.

My issue is that I am trying to print a double but the precision is being change by the user while the program is running. Printf() in C/C++ allows an asterisk to put a variable width or precision. It is unclear on my search results if this works with Java' printf() method as well.

I have the following statement:
System.out.printf("%.*f", max, val);
with max being an integer. It prints the following error message: java.util.UnknownFormatConversionException: Conversion = '*'

Am I doing it wrong please, or is it simply not available in Java?

If it is not available, would you please have any idea for that I can print this double with a different precision at run time, by using my value max?

Thank you a lot for your help.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 10 2010
Added on Jan 13 2010
3 comments
745 views