[thelist] [JS] Modulo Operator question

Kasimir K evolt at kasimir-k.fi
Mon Mar 29 14:57:22 CST 2004


This is very interesting!

Acording to JavaScript 1.5 reference at:

http://devedge.netscape.com/library/manuals/2000/javascript/1.5/reference/ops.html#1042403

"The modulo function is the integer remainder of dividing var1 by var2."

It also stats:
"Arithmetic operators take numerical values (either literals or 
variables) as their operands and return a single numerical value."

Note: no mention about values being integers.

And quick test, I give in my browsers address bar:
javascript:alert(5.2 % 2.2);
and what do I get? Doesn't look like an interger at all to me.

So to the original question: no, you can not be sure. If either of the 
operands is float, then the result seems to be flot too.

.kasimir

>> I know that the modulo gives you the remainder from a division of
>> var1 and var2:
>>
>> var Mod = var1 % var2; // would give me the remainder of this
>> expression
>>
>> Question is - is the remainder number *always* a integer? It seems to
>> be wherever I see it used, but I wanted to make sure.
> 
> 
> Yes, its always an integer. So 5%2 = 1 because 5/2 is 2 remainder 1.
> 
> Note that modulo only works if you are dividing two integers.
> 
> Judah
> 


More information about the thelist mailing list