js 计算值所占的百分比:
function getPercentValue(arr){
        //求和
        let sum = 0;
        if(sum <= 0){
            for (let i = 0; i < arr.length; i++) {
                sum += arr[i];
            }
        }
        //10的2次幂是100,用于计算精度。
        let digits = 1;
        //扩大比例100
        let votesPerQuota = [];
        for(let i = 0; i < arr.length; i++){
            let val = arr[i] / sum * digits * 100;
            votesPerQuota[i] = val;
        }
        //总数,扩大比例意味的总数要扩大
        let targetSeats = digits * 100;
        //再向下取值,组成数组
        let seats = [];
        for(let i = 0; i < votesPerQuota.length; i++){
            seats[i] = Math.floor(votesPerQuota[i]);
        }
        //再新计算合计,用于判断与总数量是否相同,相同则占比会100%
        let currentSum = 0;
        for (let i = 0; i < seats.length; i++) {
            currentSum += seats[i];
        }
        //余数部分的数组:原先数组减去向下取值的数组,得到余数部分的数组
        let remainder = [];
        for(let i = 0; i < seats.length; i++){
            remainder[i] = votesPerQuota[i] - seats[i];
        }
        while(currentSum < targetSeats){
            let max = 0;
            let maxId = 0;
            for(let i = 0;i < remainder.length;++i){
                if(remainder[i] > max){
                    max = remainder[i];
                    maxId = i;
                }
            }
            //对最大项余额加1
            ++seats[maxId];
            //已经增加最大余数加1,则下次判断就可以不需要再判断这个余额数。
            remainder[maxId] = 0;
            //总的也要加1,为了判断是否总数是否相同,跳出循环。
            ++currentSum;
        }
        // 这时候的seats就会总数占比会100%
        return seats;
    }
let res = getPercentValue([99,90,77,10])
console.log(res);
输出:[36, 32, 28, 4]