You need to sign in to do that
Don't have an account?
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.
Try using this:
ceil stands for "ceiling," which in effect is the same as "always round up." There's also Math.floor() for rounding down when you need it.