title: Calculating Percentile Score for every value in the list
body: <p>I've been searching for a way to calculate the percentile rank for every value in a given list and I've been unsuccessful thus far.</p>
  
  <p><code>org.apache.commons.math3</code> gives you a way to fetch the pth percentile from a list of values but what I want is the opposite. I want to have a ranking for every value in the list. Is anyone aware of a library or a way in Apache commons math to achieve that?</p>
  
  <p>For example: given a list of values <code>{1,2,3,4,5}</code>, I'd want to have the percentile rank for every value with the maximum percentile being 99 or 100 and the minimum being 0 or 1.</p>
  
  <p>Updated code:</p>
  
  <pre><code>public class TestPercentile {
  
  public static void main(String args[]) {
      double x[] = { 10, 11, 12, 12, 12, 12, 15, 18, 19, 20 };
      calculatePercentiles(x);
  }
  
  public static void calculatePercentiles(double[] arr) {
      for (int i = 0; i &lt; arr.length; i++) {
          int count = 0;
          int start = i;
          if (i &gt; 0) {
              while (i &gt; 0 &amp;&amp; arr[i] == arr[i - 1]) {
                  count++;
                  i++;
              }
          }
          double perc = ((start - 0) + (0.5 * count));
          perc = perc / (arr.length - 1);
          for (int k = 0; k &lt; count + 1; k++)
              System.out.println("Percentile for value " + (start + k + 1)
                      + " = " + perc * 100);
      }
  }}
  
  Sample Output: 
  Percentile for value 1 = 0.0
  Percentile for value 2 = 11.11111111111111
  Percentile for value 3 = 22.22222222222222
  Percentile for value 4 = 50.0
  Percentile for value 5 = 50.0
  Percentile for value 6 = 50.0
  Percentile for value 7 = 50.0
  Percentile for value 8 = 77.77777777777779
  Percentile for value 9 = 88.88888888888889
  Percentile for value 10 = 100.0
  </code></pre>
  
  <p>Can someone let me know if this is correct and if there is a library for doing this more cleanly?</p>
  
  <p>Thank you!</p>