Stop to! rounding?

H. S. Teoh hsteoh at quickfur.ath.cx
Tue Jul 2 22:21:52 PDT 2013


On Tue, Jul 02, 2013 at 10:14:33PM -0700, Ali Çehreli wrote:
[...]
> import std.stdio;
> import std.conv;
> 
> void main()
> {
>     auto a = to!double("151.42499");
>     writefln("%.60f", a);
> }

I wouldn't write it like that; IMO it's better to write:

	writefln("%.*f", double.dig, a);

So that you don't give the wrong impression that there are more digits
than are actually there. Using double.dig also lets you see all the
digits that *are* there, not a rounded value, that the OP was
complaining about.


T

-- 
The easy way is the wrong way, and the hard way is the stupid way. Pick one.


More information about the Digitalmars-d-learn mailing list