ShowAll Questionssorted byDate Posted
bohemianguy100

# math fuctions

I'm trying to calculate the number of days based on total hours in a month for an 8 hour workday.

For example, if there are 40 hours specificed for a month: 40 / 8 = 5 days

The problem is when I'm calculating hours that have a remainder.

For example, if there are 12 hours for a month: 12 / 8 = 1.5 days

Or, if there are 25 hours for a month: 25 / 8 = 3.125 days

Or, if there are 4 hours for a month: 4 / 8 = 0.5 days

Anytime there is a remainder, the calculation should round to the next highest integer value.

1.5 should round to 2

3.125 should round to 4

0.5 should round to 1

etc.

Here is what I was trying:

```Integer recurrenceInterval = math.round((s.Hours__c / 8)-1);

Integer hours = math.round(s.Hours__c);

Integer remainder = math.mod(hours,8);

if (remainder > 0) {
recurrenceInterval = recurrenceInterval + 1;
}```

My code isn't adding the necessary day in some instances.

Thanks for any help.

`Math.ceil(s.Hours__c / 8)`