Copy link to clipboard
Copied
I have several numeric formatted fields scripted to be added, with a sum displayed in a "total" field. Sometimes the total is correct, so that for instance $50.00 + $50.00 totals as $100.00, but at other times $50.00 + $50.00 appears concatenated, as $5050.00. I cannot find what may be causing this and would appreciate help correcting this.
Copy link to clipboard
Copied
Something is causing one of the values to appear to be a string.
What is the format of the fields?
Are there any null or empty fields being used in the calculation?
One can use the Number constrictor to force values to numerics.
If you include the $ symbol you are creating a string not a number.
Copy link to clipboard
Copied
Hi.
To force values to numerics you can multiply by 1:
var nTotal = (50.00 * 1) + (50.00 * 1);
var sTotal = "$" + nTotal;
Copy link to clipboard
Copied
I apologize for not responding sooner. Since the switch from AcrobatUsers.com I did not know I needed to log in and look at my content to see answers; I thought I would receive an email notification that someone had answered.
It's been 2 months since my post. I had created three variables, the first two referencing numeric formatted text fields [example var num1 = +getField("num1").value and var num2 = +getField("num2").value] . (I may have been referencing the fields as "this.getField" instead of "+getField" but don't recall now.) The third variable did not reference a field but rather was a variable adding the first two, as in "var num3 = num1 + num2" and then I would assign the value of var num3 to a third field, with the result being, for example, 50 + 50 = 5050 instead of 100.
This was resolved by creating another field to receive the value of num1 + num2
Copy link to clipboard
Copied
Post your full, actual code, please.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now