I'd like to vary the precision of a double representation in a string I'm formatting based on user input. Right now I'm trying something like:
String foo = String.format("%.*f\n", precision, my_double);
however I receive a java.util.UnknownFormatConversionException
. My inspiration for this approach was C printf and this resource (section 1.3.1).
Do I have a simple syntax error somewhere, does Java support this case, or is there a better approach?
Thanks all.
Edit
I suppose I could do something like:
String foo = String.format("%." + precision + "f\n", my_double);
but I'd still be interested in native support for such an operation.