- To: coders@xxxxxxxxxxx
- Subject: fwd: Re: [coders] Python newbie question
- From: benno@xxxxxxxxxxxxxxxxxxxxx (Ben Leslie)
- Date: Tue, 14 Nov 2006 12:17:24 +1100
- User-agent: Mutt/1.4.2.2i
On Tue Nov 14, 2006 at 11:49:53 +1100, Carlo Sogono wrote:
>I'm attempting to learn Python and have been playing around with it for
>the past few days. Why is my output not too smart:
>
>>>> 8.0 + 0.45
>8.4499999999999993
>
>However this seems ok:
>
>>>> 0.45 + 0.55
>1.0
First you need to read this:
http://www.cs.utah.edu/~zachary/isp/applets/FP/FP.html
Then consider using a decimal/fixed-point type rather than floating point type
if that is what you need. (Hint: if you are dealing with money, you probably want
fixed-point).
Benno