Copy link to clipboard
Copied
I am trying to create an Fillable PDF Invoice for my business that I can fill out in Arobat that will auto calculate my total hours in decimal when I add them in the field.
Example: (HH:MM) 3:50 = (decimal time) 3.83
I realized it may need a javascript formula to do this.
I don't quite know how to set this up, where to put the javascript and etc. Appreciate the help.
Here is how I have it setup.
To convert time to decimal, you can use this as custom calculation script of 'decimal' field (change field names in script for other fields:
function convertTimeToDecimal(timeStr) {
var parts = timeStr.split(':');
if (parts.length === 2) {
var hours = parseInt(parts[0], 10);
var minutes = parseInt(parts[1], 10);
return hours + minutes / 60;}
return 0;
}
var timeInput = this.getField("hh:MM 1").value;
event.value = convertTimeToDecimal(timeInput).toFixed(2);
Copy link to clipboard
Copied
To convert time to decimal, you can use this as custom calculation script of 'decimal' field (change field names in script for other fields:
function convertTimeToDecimal(timeStr) {
var parts = timeStr.split(':');
if (parts.length === 2) {
var hours = parseInt(parts[0], 10);
var minutes = parseInt(parts[1], 10);
return hours + minutes / 60;}
return 0;
}
var timeInput = this.getField("hh:MM 1").value;
event.value = convertTimeToDecimal(timeInput).toFixed(2);
Copy link to clipboard
Copied
This worked! Thanks so much!
Copy link to clipboard
Copied
Hi @Keeemara
We are glad to hear that it worked for you.
Marking a reply or response “Correct” will help future users with the same issue quickly identify the correct answer.
~Amal