So the problem I have is with rounding. Here is the little code I have (there is more and if requested I can post it here, but my question is more general):
days are actually calculated as dropoffDate-pickupDate and I'm getting results like 1.25, 2.89, 3.11 etc etc..Code:
days = calculateDayCount(pickupDate, dropoffDate);
root_days = Math.round(days);
days_count = root_days;
return ["ok", 0, 0];
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
1 day 1.5 hours - we'll charge for 1 day
1 day 2.5 hours - we'll charge for 2 days
2 day 0.5 hours - we'll charge for 2 days
2 days 5 hours we'll charge for 3 days
So the question is that how can i round appropriate way to calculate charges properly. I assume 1 hour is appox. 0.04 day.
Thank you guys.. again if you think you need the full code i can post here with the first request.
p.s. I'm thinking that i need to use math.floor here somehow, but can't really think how..