Re: Rounding double
CBFalconer said:
On my system, it gives 0.2999999999999 99988898, which doesn't even get the
first digit right.
--
Richard Heathfield <http://www.cpax.org.uk >
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
CBFalconer said:
Richard Heathfield wrote:
... snip ...
>
Hunh? How about:
>
double r = 0.33, s;
>
s = (int)((r * 10.0) + 0.5) / 10.0;
>
which, according to me, gives the desired value in s within the
accuracy limits of doubles.
>jacob navia said:
>>
>>
>>
>>
>Show me 0.33 rounded to one decimal place.
>>And it IS possible to round correctly a double precision number.
>Show me 0.33 rounded to one decimal place.
Hunh? How about:
>
double r = 0.33, s;
>
s = (int)((r * 10.0) + 0.5) / 10.0;
>
which, according to me, gives the desired value in s within the
accuracy limits of doubles.
first digit right.
--
Richard Heathfield <http://www.cpax.org.uk >
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Comment