[Tutor] Need more precise digits
Sat, 01 Dec 2001 16:00:20 -0500
You really want something like:
avgsize = float(totalsize)/float(groups)
In older Python's:
22/10 = 2
float(22/10) = float(2) = 2.0
You need to convert to float BEFORE doing the division.
Mike Yuen wrote:
> I've trying to calculate an average and it looks like i'm losing some
> precision in digits.
> For example: i've got the following formula
> avgsize = float(totalsize/groups)
> both totalsize and groups are integers
> I've got 10 groups
> sizes are:
> 2+3+2+2+3+2+2+2+2+2 = 22
> I should get 22/10 = 2.2.
> What I get is 2.0. How do I get this missing 2 tenths? As you can see
> from the above, I already casted to a float.
> Tutor maillist - Tutor@python.org
1 Court Street, Suite 378
Lebanon, NH 03766-1358