python - rescale a value between two numerical ranges
<p>I am trying to convert a value, comprised in the range of two integers, to another integer comprised in an other given range. I want the output value to be the corresponding value of my input integer (respecting the proportions). To be more clear, here is an example of the problem I'd like to solve:</p>

<ul>
<li>Suppose I have three integers, let's say 10, 28 and 13, that are comprised in the range (10, 28). 10 is the minimum possible value, 28 the maximum possible value. </li>
<li>I want, as output, integers converted to the 'corresponding' number in the range (5, 20). In this precise example, 10 would be converted to 5, 28 to 20, and 13 to a value between 5 and 20, rescaled to keep the proportions intacts. Afterwards, this value is converted to integer. </li>
</ul>

<p>How is it possible to achieve such 'rescaling' in python ? I tried the usual calculation <code>(value/max of first range)*max of second range</code> but it gives wrong values except in rare cases. </p>

<p>At first I had problems with the division with <code>int</code>in python, but after correcting this, I still have wrong values. For instance, using the values given in the example, <code>int((float(10)/28)*20)</code> will give me 7 as result, where it should return 5 because it's the minimum possible value in the first range. </p>

<p>I feel like it is a bit obvious (in terms of logic and math) and I am missing something. </p>