If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Enjoy an ad free experience by logging in. Not a member yet? Register.

days are actually calculated as dropoffDate-pickupDate and I'm getting results like 1.25, 2.89, 3.11 etc etc..

So what the Math.round(days) does, is it rounds as usual and stores in root_days, but the problem is that I need it rounded not as usual. Here is why:
The code will work for a service calculation and if service is provided for more then 2 hours, the service charges for the whole day. Example

"If you can't explain it simply, you don't understand it well enough”
“Everything should be as simple as it is, but not simpler.”
- both quotes Albert Einstein (German born American Physicist who developed the special and general theories of relativity. Nobel Prize for Physics in 1921. 1879-1955)

All the code given in this post has been tested and is intended to address the question asked.
Unless stated otherwise it is not just a demonstration.

@007julien can you please explain what exactly this Math.floor(days+11/12) achieves I'm asking this because...

@felgall & Philip M variables days_count and root_days are used elsewhere in the code also, so I thought i can do this (I know i can assign d to anyting after this, but still didn't want to confuse myself)

No. You have been given two scripts - both work, but julien007's is slicker. Don't ask for help and then ignore it.

var d = Math.floor(days+11/12);

11/12 of a day is (24-2) = 22 hours, so if you add 11/12 to the value of days (say 2.09) you get 3.00666666. Math.floor then resolves to 3 (days).
Likewise if days = 2.08 adding 11/12 gives 2.9966666, which resolves to 2 days.

That is what you asked for.

All the code given in this post has been tested and is intended to address the question asked.
Unless stated otherwise it is not just a demonstration.