• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

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

315

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

Community Expert , 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 split

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

Votes

Translate

Translate
Community Expert ,
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

Votes

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

LATEST

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

Votes

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