[Tutor] Format strings for variables - how?
Thu, 8 Feb 2001 00:28:39 -0700
* Viktor Lakics <email@example.com>:
> Hi dear Tutors,
> Sorry for the basic question, I am just a starter in Python...
This is what tutor is for!
> print "%0.2f" %(a/b)
> The above code gives me 0.00 as a result, while I wanted to get
The reason is that the numbers you are dividing are not floats. Because of
that, you are doing integer division.
>>> a = 1.0
>>> b = 3
print "%0.2f" %(a/b)
gives 0.33. You must add a decimal point to one (or more) of the numbers.