Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Math - Divide & leave remainder [duplicate]

Tags:

jquery

math

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
like image 634
Shannon Hochkins Avatar asked Dec 27 '12 11:12

Shannon Hochkins


1 Answers

You can use modulus operator % to get remainder after division.

Live Demo

remainder = 50 % 15;
like image 72
Adil Avatar answered Sep 20 '22 02:09

Adil