Stop to! rounding?
Ali Çehreli
acehreli at yahoo.com
Tue Jul 2 22:14:33 PDT 2013
On 07/02/2013 10:09 PM, Jonathan M Davis wrote:
> On Wednesday, July 03, 2013 07:04:47 cal wrote:
>> void main()
>> {
>> double d = 151.42499;
>> assert(d == 151.42499);
>> }
>>
>> The rounding occurs in writeln surely.
>
> That's true because _both_ of the floating point values there get
rounded to
> 151.425,
The value that can be stored is not 151.42499, nor 151.425.
import std.stdio;
import std.conv;
void main()
{
auto a = to!double("151.42499");
writefln("%.60f", a);
}
Prints:
151.424990000000008194547262974083423614501953125000000000000000
> writeln is not doing anything wrong.
True. It is using its default floating point precision, 6.
Ali
More information about the Digitalmars-d-learn
mailing list