simple problem....but I have no clue why its not working.....

if (w[0] > m[1]):
      temp = ((w[0]-m[1])/w[0])*100
      print temp

For some reason temp is always 0.........I want a double percentage difference between the two values....

Please guys..help me out here......after 500 lines of code ...I am stuck here......my assignment is due tonight..... :sad:

how the hell do I get a float value? :sad:

12 Years
Discussion Span
Last Post by shafter111

Hi shafter111,

If you are dividing an integer by some other number and you want the quotient to be a float, you need to cast the integer to a float. In other words:

a, b = 8, 3
temp = ((a-b)/a)*100     # Gives you zero


a, b = 8, 3
temp = (float(a-b)/a)*100     # Gives you 62.5

If you need greater precision than that provided by float(), look up the decimal module in the tutorial:

Guido van Rossum's Python Tutorial

Hope that helps.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.