原 java实现Excel PERCENTILE.INC 函数
版权声明:本文为博主原创文章,请尊重他人的劳动成果,转载请附上原文出处链接和本声明。
本文链接:https://www.91mszl.com/zhangwuji/article/details/1447
public static void main(String[] args) {
double[] data={96, 60, 66, 70, 72, 78, 82, 93, 93};
double p=0.5;
double aa=percentile(data, p);
System.out.println(aa);
}
public static double percentile(double[] data, double p){
int n = data.length;
Arrays.sort(data);
double px = p * (n-1);
int i = (int)java.lang.Math.floor(px);
double g = px - i;
if(g==0){
return data[i];
} else{
return (1-g) * data[i] + g * data[i+1];
}
}
执行结果:
78.0
参考资料:
https://zh-cn.extendoffice.com/excel/functions/excel-percentile-inc-function.html
https://www.iteye.com/blog/963084302-2252508
2023-07-17 15:50:00 阅读(446)
名师出品,必属精品 https://www.91mszl.com
博主信息