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:

## All 2 Replies

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

While:

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:

Hope that helps.

Thanks man......really appretiate the help
you rock!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.