How does the modulus operator work?

前端 未结 5 1662
忘了有多久
忘了有多久 2020-11-27 17:19

Let\'s say that I need to format the output of an array to display a fixed number of elements per line. How do I go about doing that using modulus operation?

Using C

5条回答
  •  隐瞒了意图╮
    2020-11-27 18:12

    This JSFiddle project could help you to understand how modulus work: http://jsfiddle.net/elazar170/7hhnagrj

    The modulus function works something like this:

         function modulus(x,y){
           var m = Math.floor(x / y);
           var r = m * y;
           return x - r;
         }
    

提交回复
热议问题