Specifying precision in %(...%) print format
H. S. Teoh
hsteoh at quickfur.ath.cx
Sun Oct 14 22:43:06 PDT 2012
I have an array of reals that I want to format with writefln, but the
precision field needs to be passed in a variable. For a single real, it
would be writefln("%.*f", precision, x); but when I try this:
int precision = ...;
real[] array = ...;
writefln("%(%.*f, %)", precision, array);
I get a runtime exception with the message "integral". I assume that's
because %(%) is expecting an array, but sees an int, so it fails. But
swapping the order of parameters doesn't help either:
writefln("%(%.*f, %)", array, precision);
produces "floating point format failure".
What's the right way to do this?
T
--
Trying to define yourself is like trying to bite your own teeth. -- Alan Watts
More information about the Digitalmars-d-learn
mailing list