title: Percentage calculation between two values
body: <p>I want to obtain a result between 0.0 and -0.5. I have the values: MIN = x, MAX = y and IN = x. The value MIN should result in a percent of -0.5% and MAX 0.0%. For example, if the value of MIN is 240px, the MAX is 600px and the IN is 360px the IN should result a percent of -0.33%. But I don't know how to do this calculation.</p>
  
  <p>P.S.: the IN can't be higher than 0.0 or lower than -0.5.
  P.S.2: sorry about my english.</p>
  
  <p>The code I tried, but didn't work:</p>
  
  <pre><code>float percent = (((currentX / max) * min) / (max - min) * (-1)); Animation openNavigationDrawer = new TranslateAnimation( Animation.RELATIVE_TO_PARENT, percent, Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 0.0f); openNavigationDrawer.setDuration(200); navigationDrawer.setAnimation(openNavigationDrawer);
  </code></pre>
  
  <p>And the second one (worked, but was not good):</p>
  
  <pre><code>float percent = -0.0f;
      float posDividerDefault = max / 12, 
      posDividerOne = min + posDividerDefault, posDividerTwo = posDividerOne + posDividerDefault, 
      posDividerThree = posDividerTwo + posDividerDefault, posDividerFour = posDividerThree + posDividerDefault, 
      posDividerFive = posDividerFour + posDividerDefault, posDividerSix = posDividerFive + posDividerDefault;
  
      if (currentX &lt; posDividerOne) {
          percent = -0.5f;
  
      } else if (currentX &gt; posDividerOne &amp;&amp; currentX &lt; posDividerTwo) {
          percent = -0.45f;
  
      } else if (currentX &gt; posDividerTwo &amp;&amp; currentX &lt; posDividerThree) {
          percent = -0.4f;
  
      } else if (currentX &gt; posDividerThree &amp;&amp; currentX &lt; posDividerFour) {
          percent = -0.3f;
  
      } else if (currentX &gt; posDividerFour &amp;&amp; currentX &lt; posDividerFive) {
          percent = -0.2f;
  
      } else if (currentX &gt; posDividerFive &amp;&amp; currentX &lt; posDividerSix) {
          percent = -0.1f;
  
      } else if (currentX &gt; posDividerSix) {
          percent = -0.0f;
  
      }
  </code></pre>