Modulo in JavaScript - large number

前端 未结 6 1848
情深已故
情深已故 2021-01-07 20:39

I try to calculate with JS\' modulo function, but don\'t get the right result (which should be 1). Here is a hardcoded piece of code.

var checkSum = 21050170         


        
6条回答
  •  再見小時候
    2021-01-07 21:19

    Finally, my solution:

    function modulo (divident, divisor) {
        cDivident = '';
        cRest = '';
    
        for each ( var cChar in divident ) {
            cOperator = cRest + '' + cDivident + '' + cChar;
    
            if ( cOperator < divisor ) {
                cDivident += '' + cChar;
            } else {
                cRest = cOperator % divisor;
                if ( cRest == 0 ) cRest = '';
                cDivident = '';
            }
    
        }
    
        return cRest;
    }
    

提交回复
热议问题