total and utter newbie

Jere Kahanpaa kahanpaa at gstar.astro.helsinki.fi
Thu Nov 14 09:16:01 EST 2002


Hi.

John Hunter <jdhunter at nitace.bsd.uchicago.edu> wrote:
>>>>>> "rockbox" == rockbox  <rockboxb at webmail.co.za> writes:

>     rockbox> Hi.  I hope that this is the right group to post this
>     rockbox> problem in. If not then I appologise.

> Ahh yes, the oldest newbie problem in the book :-)

> In current versions of python (as in C and many other programming
> languages) an integer divided by an integer returns an integer, so

> x = 3/2      #x is 1

> but if either number is a floating point number, then the division you
> are expecting is used

> x = 3.0/2.0  # x = 1.5

> The trick is to add a decimal point and a 0 to your number unless you
> want integer behavior

> x = 3.0/2  # this is also 1.5

> This is being phased out of python, and is slated for destruction.

> Recent versions of python (2.2?) allow you to use

> from __future__ import division

A more backwards-portable trick is doing a explicit conversion to a
floating point number before division.

vat = float(rate)/100*value

Jere Kahanpää
-- 
It's hard to think outside the box when you ARE the box.
                            - unknown, alt.religion.kibology 



More information about the Python-list mailing list