Copy link to clipboard
Copied
Greetings,
(Using Adobe Acrobat Pro)
I am currently facing an issue where my calculation of time difference functions however it does not recognize the need to round. For example, in the image below the Hours of 1.16 should be 1.17 - the same is for the 0.41 Hours needing to be 0.42.
Thank you in advance for any assistance!
This is the code I am using in the Custom Calculation Scripts of each Hours field:
var start = this.getField("Start Time").valueAsString;
var finish = this.getField("End Time").valueAsString;
if (start=="" || finish=="") event.value = "";
else {
var startArr = start.split(":") ;
var finishArr = finish.split(":") ;
var hourDiff = finishArr[0] - startArr[0];
var minDiff = Math.floor(((finishArr[1] - startArr[1]) / 60)*100);
if (minDiff<0) {hourDiff--; minDiff += 100;}
if (hourDiff<0) hourDiff+=24;
if (minDiff.toString().length == 1) minDiff = '0' + minDiff;
event.value = hourDiff + "." + minDiff;
}
Try using Math.round instead of Math.floor, then.
Copy link to clipboard
Copied
Try using Math.round instead of Math.floor, then.