Round up to nearest quarter hour
I have a form with several drop-down fields, representing rooms.
The dropdown values are from 1-10.
They are multiplied by a certain amount to reflect cleaning time per room.
In a text field I add up the value of the dropdown fields.
The value in the text field represents total minutes.
None of the fields has a format applied.
I want to convert the text field value to hours and minutes, then round UP to the nearest 15 minutes.
So, if the total minutes is 85, it should display as 01:25 and be rounded up to 01:30
Or, if the total minutes is 80, it should display as 01:20 and be rounded up to 01:30
Currently, I am using the following Javascript to get the value to display as hours and minutes (though I don't really understand it from var nHours onwards):
var st = this.getField("Storeys").value * 10;
var ki = this.getField("Kitchen").value * 30;
var kd = this.getField("K/D").value * 30;
var sw = this.getField("S/W").value * 10;
var be = this.getField("Bed").value * 10;
var di = this.getField("Dining").value * 20;
var lf = this.getField("Living").value * 20;
var co = this.getField("Cons").value * 20;
var fb = this.getField("FullBath").value * 30;
var sh = this.getField("Shower").value * 20;
var ba = this.getField("BathOnly").value * 20;
var wc = this.getField("W/C").value * 10;
var prep = 5;
var TotalMin = st + ki + kd + sw + be + di + lf + co + fb + sh + ba + wc + prep;
var nHours = TotalMin / 60;
var nMin = TotalMin % 60;
var sFormat = "%,002d";
sFormat += ":";
sFormat += "%,002d";
if (st == "" && ki == "" && kd == "" && sw == "" && be == "" && di == "" && lf == "" && co == "" && fb == "" && sh == "" && ba == "" && wc == "") {event.value = "";}
else event.value = util.printf(sFormat, nHours, nMin);
