Stop to! rounding?
cal
callumenator at gmail.com
Tue Jul 2 22:04:47 PDT 2013
On Wednesday, 3 July 2013 at 04:32:15 UTC, Jonathan M Davis wrote:
> On Wednesday, July 03, 2013 06:23:12 Josh wrote:
>> writeln(to!double("151.42499")); //prints 151.425
>>
>> Is there any way to stop this rounding?
>
> No. double can't hold the value 151.42499. There are _tons_ of
> values that it
> can't hold exactly. The same goes for float and real. Floating
> point values are
> rounded all the time. Note that
>
> double d = 151.42499;
> writeln(d);
>
> prints exactly the same thing as your example.
>
> - Jonathan M Davis
void main()
{
double d = 151.42499;
assert(d == 151.42499);
}
The rounding occurs in writeln surely.
More information about the Digitalmars-d-learn
mailing list