Stop to! rounding?
Jonathan M Davis
jmdavisProg at gmx.com
Tue Jul 2 23:19:32 PDT 2013
On Tuesday, July 02, 2013 22:14:33 Ali Çehreli wrote:
> 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.
Ah. You learn new things every day. Well, I stand corrected. I was half right.
It isn't 151.42499, but writeln _is_ rounding. I really don't like dealing
with floating point numbers.
- Jonathan M Davis
More information about the Digitalmars-d-learn
mailing list