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

calculate a 20+ digit field

New Here ,
Apr 15, 2019 Apr 15, 2019

Copy link to clipboard

Copied

I am trying to copy a fields contents so that I can have one set of fields be changed, and another set be read-only. I added a custom calculation script to one of the fields and everything seems to work - except... I have have a 23 character long field that starts to mess up after 16 characters of data. After 16 it starts being inaccurate. I'm guessing that this is due to the data type that the field has allocated. Stranger still - after it gets passed 20 digits or so, it starts displaying in scientific notation. Does anyone know how to fix this? Should I go about doing this a different way?

TOPICS
Acrobat SDK and JavaScript , Windows

Views

1.4K

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

LEGEND , Apr 15, 2019 Apr 15, 2019

This is not something you can fix if you want to calculate. Almost all programming languages have either a largest number (often around 2 billion) or a highest accuracy (often around 15 digits). JavaScript is the second.

If on the other hand you just need very long strings of digits and never calculate with them, you can fix this by using format None as noted, and always using .valueAsString rather than .value in JavaScript.

Votes

Translate

Translate
New Here ,
Apr 15, 2019 Apr 15, 2019

Copy link to clipboard

Copied

This is what I have as the running script

var numberOfRows = 35;

//get the correlating fields contents, and then paste

function calc(rowNumber, colNumber, colName, tableColName) {

     for (i = 0; i < numberOfRows; i++) {

          var x = this.getField(colName + "." + (rowNumber + i)).value;

          this.getField(tableColName + " " + colNumber + "." + (rowNumber + i)).value = x;

     }

}

calc(0, 1, "Merchant Name", "Table Col");

calc(0, 2, "Transaction Amount","Table Col");

calc(0, 3, "Transaction Date", "Table Col");

calc(0, 4, "EFT Web Ref #", "Table Col");

calc(0, 5, "23 Digit ARN #", "Table Col");

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
Community Expert ,
Apr 15, 2019 Apr 15, 2019

Copy link to clipboard

Copied

Is there a reason your numbers need to be so large?  i.e., that the calculation needs to handle such large numbers? If these are id number of some type, then they should be handled as text strings. Don't format them as numbers.

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 ,
Apr 15, 2019 Apr 15, 2019

Copy link to clipboard

Copied

Your assumption was correct. It is a type of ID number yes, so there is no calculation needed. I knew that I had to make it a string, I just didn't know to use .valueAsString. After I made the appropriate change in the code, and then made sure I was formatting as "none" everything worked great! Thanks guys! I particularly appreciate @Test Screen Name for his in depth response to my question. You all have done a great job at helping me understand my problem.

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
Community Expert ,
Apr 15, 2019 Apr 15, 2019

Copy link to clipboard

Copied

Use the format "None" for the fields.

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
LEGEND ,
Apr 15, 2019 Apr 15, 2019

Copy link to clipboard

Copied

This is not something you can fix if you want to calculate. Almost all programming languages have either a largest number (often around 2 billion) or a highest accuracy (often around 15 digits). JavaScript is the second.

If on the other hand you just need very long strings of digits and never calculate with them, you can fix this by using format None as noted, and always using .valueAsString rather than .value in JavaScript.

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
LEGEND ,
Apr 15, 2019 Apr 15, 2019

Copy link to clipboard

Copied

LATEST

The designers of JavaScript decided to make it magically convert between strings and numbers as needed, to make it easier to program in, and other decisions so people didn't get too many error message. Personally, I hate this, because we see so many problems caused by things which shouldn't be numbers being treated as numbers, and also spelling errors being treated as new variables. I like languages where you have to start by listing all the variables you will use, and what type of data they hold. Clearly, others hold different views.

There is something called "beginners depression" in programming, which is partly caused by very strict language rules. People learning Algol 68 would take weeks before they could write a program that would start to run. But I do wonder if we replace this by beginner's bafflement, where the code runs quickly but it takes weeks to get the result you wanted.

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