Message122676
> I get 114.999999999.
How many '9's are there on what you're getting? If you really get '114.999999999' then something surprising is happening. If, on the other hand, you get '114.99999999999999', then it's all as expected. :-)
The issue is one that affects the vast majority of popular programming languages, namely that numbers are stored internally in binary, so a number like 1.15 isn't exactly representable---you end up storing a (very good) approximation to 1.15 instead. And then when you multiply by 100, you end up with a (very good) approximation to 115.0.
I highly recommend reading the floating-point section of the Python tutorial for an explanation of what's going on under the hood.
http://docs.python.org/dev/py3k/tutorial/floatingpoint.html |
|
Date |
User |
Action |
Args |
2010-11-28 16:26:26 | mark.dickinson | set | recipients:
+ mark.dickinson, ipcctv |
2010-11-28 16:26:25 | mark.dickinson | set | messageid: <1290961585.95.0.758222592283.issue10564@psf.upfronthosting.co.za> |
2010-11-28 16:26:24 | mark.dickinson | link | issue10564 messages |
2010-11-28 16:26:24 | mark.dickinson | create | |
|