mh_and

12-05-2012, 08:14 AM

Hello guys,

A newbie here and newbie in javascript. I'm just learning and really can't do much but read the code, understand and do some changes. Will much appreciate your help here.

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 = calculateDayCount(pickupDate, dropoffDate);

getPrices(days);

root_days = Math.round(days);

days_count = root_days;

$j('#day_count').val(days_count);

$j('#header_days').html(days_count);

return ["ok", 0, 0];

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

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

etc etc..

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..

A newbie here and newbie in javascript. I'm just learning and really can't do much but read the code, understand and do some changes. Will much appreciate your help here.

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 = calculateDayCount(pickupDate, dropoffDate);

getPrices(days);

root_days = Math.round(days);

days_count = root_days;

$j('#day_count').val(days_count);

$j('#header_days').html(days_count);

return ["ok", 0, 0];

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

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

etc etc..

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..