Re: Why the nonsense number appears?
- From: Yu-Xi Lim <yuxi@xxxxxxxxxxxxxx>
- Date: Mon, 31 Oct 2005 04:36:37 -0500
Johnny Lee wrote: <snip>
Why are there so many nonsense tails? thanks for your help.
I guess you were expecting 0.039? You first need to understand floating point numbers:
http://docs.python.org/tut/node16.html
What you see are the effects of representation errors.
The solution is presented here: http://www.python.org/peps/pep-0327.html
But briefly, it means your code should read:
from decimal import * t1 = "1130748744" t2 = "461" t3 = "1130748744" t4 = "500" time1 = t1+"."+t2 time2 = t3+"."+t4 print time1, time2 Decimal(time2) - Decimal(time1) .
- Prev by Date: Re: Why the nonsense number appears?
- Next by Date: Re: Why the nonsense number appears?
- Previous by thread: Re: Why the nonsense number appears?
- Next by thread: Re: Why the nonsense number appears?
- Index(es):