Possible Duplicate:
Integer division in JavaScript
Hopefully this is a simple question, basically I need to do this:
divider = 15
number = 50
Obviously 15 can be divided into 50 3 times with a remainder of 5, is there a simple way I can achieve this with math?
Obviously just dividing 50 by 15 will give me a rounded figure which I just want the lowest possible result and if there is anything left over and it's less than 15 just leave it alone.
Any help?
Cheers, Shannon
EDIT:
Thanks to Adil:
x = 50;
y = 15;
res = x % y;
x = (x - res) / y;
// x = 3
You can use modulus operator %
to get remainder after division.
Live Demo
remainder = 50 % 15;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With