How to get percentile in "reverse" in php

I am not sure if this is correct title. I have let’s say 3000 members, each one is ranked based on number of points. Max rank is 3000, min rank is 1. I need to check for each member on which top 10% is the member (top 10%, top 20%, …, top 90%) based on their rank.

There are some answers how to get percentile, but these functions only check if the number is within percentile when you provide all numbers and percentile number. I need in reverse order, for example I have max rank number, min rank number and the member rank. All rank numbers are sequential. Now I need to get within which percentile is this number. Or more precisely within which 10%. Any idea how to get this?

>Solution :

Do you really need the min rank since you have a ranking which should obviously go to 1.

You need to be able to calculate the user percentage and then round it to the nearest 10%.

It could look like this:

function calculatePercentage($rank, $total){
    return ($rank/$total)*100;
function roundToNearestTen($value){
    return ceil($value / 10) * 10;

function getRank($rank, $total){
    return roundToNearestTen(calculatePercentage($rank, $total));

$rank = 99;
$total = 1000;

echo getRank($rank, $total).'%';
//Output: 10%

Leave a Reply