calculate a 20+ digit field

New Here ,
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?

Most Valuable Participant
Correct answer by Test Screen Name | Most Valuable Participant

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.

TOPICS
Acrobat SDK and JavaScript, Windows

Views

87

Likes

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

calculate a 20+ digit field

New Here ,
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?

Most Valuable Participant
Correct answer by Test Screen Name | Most Valuable Participant

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.

TOPICS
Acrobat SDK and JavaScript, Windows

Views

88

Likes

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
Apr 15, 2019 0
New Here ,
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");

Likes

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
Reply
Loading...
Apr 15, 2019 0
Adobe Community Professional ,
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.

Likes

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
Reply
Loading...
Apr 15, 2019 0
New Here ,
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.

Likes

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
Reply
Loading...
Apr 15, 2019 0
Adobe Community Professional ,
Apr 15, 2019

Copy link to clipboard

Copied

Use the format "None" for the fields.

Likes

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
Reply
Loading...
Apr 15, 2019 0
Most Valuable Participant ,
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.

Likes

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
Reply
Loading...
Apr 15, 2019 0
Most Valuable Participant ,
Apr 15, 2019

Copy link to clipboard

Copied

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.

Likes

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
Reply
Loading...
Apr 15, 2019 0