I'm trying to write this equation with python:
(1/100)*((102/65520)*x - 1)*10
But I don't know how to apply the fractions in order to get the right result.
Does anyone know how I should write it?
I'm trying to write this equation with python:
(1/100)*((102/65520)*x - 1)*10
But I don't know how to apply the fractions in order to get the right result.
Does anyone know how I should write it?
You are using 'integer' division, which is default in python 2, so results are being rounded (1/100 is equal to 0, nooooo!).
You have too make the division 'floaty'. I can think of two solutions:
1) Make the dividends become floats directly
(1.0/100)*((102.0/65520)*x - 1)*10
You can cast integers into floats with float(), too. Then, float(102) is equivalent to 102.0
(float(1)/100)*(float(102)/65520)*x - 1)*10
2) Use float division (default in Python 3):
from future import __division__
Now / is float division and your code line works as it is. Note: You should use '//' for integer division, just in case.
Credits on the second one for: How can I force division to be floating point? Division keeps rounding down to 0