[Tutor] Re: integers and float
Derrick 'dman' Hudson
dman@dman.ddts.net
Sat, 20 Jul 2002 21:23:29 -0500
--Kj7319i9nmIyA2yE
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
On Fri, Jul 19, 2002 at 09:14:46AM -0700, MIG wrote:
| I've got a question with float and $.
No. No. No. No. No.
Never never ever use floating point for handling money. Always use
integers or fixed point.
If you want a demonstration of why, try this :
>>> print "%.40f" % 0.1
0.1000000000000000055511151231257827021182
For another example that doesn't involve binary, use a pencil and
paper and rewrite the expresion
1/3
in decimal. No, don't approximate it. Write it *exactly*. Ok,
nevermind I don't want to kill you. (you can't, it's a "repeating
decimal")
If you want to learn more about binary floating point than you ever
cared, just ask Tim Peters :-). (he's a guru with that stuff)
-D
--=20
The wise in heart are called discerning,
and pleasant words promote instruction.
Proverbs 16:21
=20
http://dman.ddts.net/~dman/
--Kj7319i9nmIyA2yE
Content-Type: application/pgp-signature
Content-Disposition: inline
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org
iEYEARECAAYFAj06GyEACgkQO8l8XBKTpRSFdACfXbPqPjVH8DeRV+tteBuLSUf3
oJkAoMpvx244Gk0AivdIJHm7pzDagD09
=U7bH
-----END PGP SIGNATURE-----
--Kj7319i9nmIyA2yE--