Split dot (".")

New Here ,
Mar 13, 2018 Mar 13, 2018

Copy link to clipboard

Copied

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.

TOPICS
Acrobat SDK and JavaScript

Views

107

Likes

translate

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct Answer

Adobe Community Professional , Mar 13, 2018 Mar 13, 2018
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 splitvar ctime1 = c1.split(/\./);

Likes

translate

Translate

Translate
Adobe Community Professional ,
Mar 13, 2018 Mar 13, 2018

Copy link to clipboard

Copied

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 PDFScripting
Use the Acrobat JavaScript Reference early and often

Likes

translate

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 14, 2018 Mar 14, 2018

Copy link to clipboard

Copied

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

Likes

translate

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines