Skip to main content
Participant
Mar 13, 2018 5:57 PM UTC
Answered

Split dot (".")

I am attempting to create a timesheet and so far have managed to calculate time based on Decimal value, however I would like to convert the decimal value to HH:MM with using simple calculations.  Reason for this is that the form will be used on IPAD and PDF expert which does not support some java script functions.

I would like to split the decimal value into two parts being (for example 2.75 to two seperate values 2 and 75.  However no matter how I attempt to escape the ful stop form the test java script below it will not split and provide the first value. (being 2)

var c1 = getField("Lunch Time 2").value;

var ctime1 = c1.split(".");

event.value = ctime1[0];

If the value of 2.75 is 2:75 and I change the javascript to split : it works no problem. Just so you know I have tried to escape the dot in many ways but cant seem to get it to work.

I have tried

("\\.")

("\.")

("//.")

("/.")

('\.")

('\\.')

('/.')

('//.')

and many others, but for the life of me dot just does not want to be the split point.  Any help would be much appricoated as I would like to be able to times the second part of the value by 60 (example 2.75 = 0.75 * 60) which will give me the minutes being 45.

The next step after this is to work how to join it all back together in a HH:MM format.

This topic is closed to new replies. Start a new post to keep the conversation going.
Thom Parker
Thom ParkerCorrect answer
Community Expert
Mar 13, 2018 7:24 PM UTC

Have you tried explicitly converting the value to a string?

var c1 = getField("Lunch Time 2").value.toString();

var ctime1 = c1.split(".");

event.value = ctime1[0];

The "." does not need to be escaped because you aren't using a regular expression. This code works just fine when executing the split command from the console.  However, PDF Expert may have some variation that is non-standard. So you might also try using a regular expression for the split

var ctime1 = c1.split(/\./);

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often

2 replies

Thom Parker
Community Expert
Thom ParkerCommunity ExpertCorrect answer
Community Expert
Mar 13, 2018 7:24 PM UTC

Have you tried explicitly converting the value to a string?

var c1 = getField("Lunch Time 2").value.toString();

var ctime1 = c1.split(".");

event.value = ctime1[0];

The "." does not need to be escaped because you aren't using a regular expression. This code works just fine when executing the split command from the console.  However, PDF Expert may have some variation that is non-standard. So you might also try using a regular expression for the split

var ctime1 = c1.split(/\./);

Translate
Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
Participant
Mar 14, 2018 9:02 PM UTC

Thank you that worked, just need to work out the decimal to time now, which is nearly completed.

Translate