Is there a "simple" js version of php's bcdiv? Because this isn't working as expected:
var x = 11,
y = Math.round(x / 7) + " + " + x % 7)
The expected result is 1 + 4, while the result i get is 2 + 4 (because 11 / 7 = 1,5 which becomes 2 after rounding).
Using Math.floor
or Math.ceil
also gives a wrong result.
What i try is to calculate the difference between two dates in weeks and days. Using bcdiv in php works fine, i just cant find a proper way in JS.
What i want: 16.04.2011 to 15.12.2013 = 139 Weeks, 1 Day
What i get: 16.04.2011 to 15.12.2013 = 137 Weeks, 1 Day
Use
parseInt
instead ofMath.round
to truncate the decimal part, like thisOutput