public static function PHPExcel_Calculation_Statistical::PERCENTRANK in Loft Data Grids 7.2
Same name and namespace in other branches
- 6.2 vendor/phpoffice/phpexcel/Classes/PHPExcel/Calculation/Statistical.php \PHPExcel_Calculation_Statistical::PERCENTRANK()
* PERCENTRANK * * Returns the rank of a value in a data set as a percentage of the data set. * *
Parameters
array of number An array of, or a reference to, a list of numbers.: * @param number The number whose rank you want to find. * @param number The number of significant digits for the returned percentage value. * @return float
File
- vendor/
phpoffice/ phpexcel/ Classes/ PHPExcel/ Calculation/ Statistical.php, line 2658
Class
- PHPExcel_Calculation_Statistical
- PHPExcel_Calculation_Statistical
Code
public static function PERCENTRANK($valueSet, $value, $significance = 3) {
$valueSet = PHPExcel_Calculation_Functions::flattenArray($valueSet);
$value = PHPExcel_Calculation_Functions::flattenSingleValue($value);
$significance = is_null($significance) ? 3 : (int) PHPExcel_Calculation_Functions::flattenSingleValue($significance);
foreach ($valueSet as $key => $valueEntry) {
if (!is_numeric($valueEntry)) {
unset($valueSet[$key]);
}
}
sort($valueSet, SORT_NUMERIC);
$valueCount = count($valueSet);
if ($valueCount == 0) {
return PHPExcel_Calculation_Functions::NaN();
}
$valueAdjustor = $valueCount - 1;
if ($value < $valueSet[0] || $value > $valueSet[$valueAdjustor]) {
return PHPExcel_Calculation_Functions::NA();
}
$pos = array_search($value, $valueSet);
if ($pos === False) {
$pos = 0;
$testValue = $valueSet[0];
while ($testValue < $value) {
$testValue = $valueSet[++$pos];
}
--$pos;
$pos += ($value - $valueSet[$pos]) / ($testValue - $valueSet[$pos]);
}
return round($pos / $valueAdjustor, $significance);
}