Stop to! rounding?

Timon Gehr timon.gehr at gmx.ch
Tue Jul 2 23:23:42 PDT 2013


On 07/03/2013 07:21 AM, H. S. Teoh wrote:
> 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.
> ...

double.dig gets you the number of significant digits in total. The 
number of significant digits after the decimal point is dependent on the 
exponent.



More information about the Digitalmars-d-learn mailing list