bug? floating point precision with std.format
Steven Schveighoffer via Digitalmars-d
digitalmars-d at puremagic.com
Mon Jun 5 08:37:42 PDT 2017
It appears that the precision parameter in std.format differs from its
meaning in printf. Is that expected behavior?
Example:
import std.stdio;
import core.stdc.stdio;
void main()
{
auto f = 20.66666;
writeln(f);
writefln("%0.3s", f);
printf("%0.3f\n", f);
}
prints:
20.6667
20.7
20.667
It appears that the precision specifier is dictating the total number of
digits on *both sides* of the decimal place. Whereas, in C, it's only
the number of digits *after* the decimal place.
I'm trying to specify 3 places of precision after the decimal. How do I
do this easily?
I'm having a hard time believing this behavior has never been reported,
but I can't find anything about it in bugzilla. Tested all the way back
to 2.040.
-Steve
More information about the Digitalmars-d
mailing list