Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 18 Oct 1997 13:58:54 +1000
From:      Bruce Evans <bde@zeta.org.au>
To:        bugs@FreeBSD.ORG, mike@NetworX.ie
Subject:   Re: Rounding up is -odd-
Message-ID:  <199710180358.NAA08402@godzilla.zeta.org.au>

next in thread | raw e-mail | index | archive | help
>Why does
>	printf "%1.2f\n" 7.005
>produce
>	7.00
>while
>	printf "%1.2f\n" 8.005
>produces
>	8.01
>?

For the same reason that
	printf "%1.20f\n" 7.005
produces
	7.00499999999999989342
and
	printf "%1.20f\n" 8.005
produces
	8.00500000000000078160

(double)7.005 isn't actually 7.005, since doubles have a finite amount
of precision and 7.005 is not exactly representable.

Bruce



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199710180358.NAA08402>