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

$50.00 + $50.00 concatenated as $5050.00.

Engaged ,
Nov 17, 2016 Nov 17, 2016

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.

TOPICS
Acrobat SDK and JavaScript
394
Translate
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 ,
Nov 17, 2016 Nov 17, 2016

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.

Translate
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 ,
Nov 20, 2016 Nov 20, 2016

Hi.

To force values to numerics you can multiply by 1:

var nTotal = (50.00 * 1) + (50.00 * 1);

var sTotal = "$" + nTotal;


Acrobate du PDF, InDesigner et Photoshopographe
Translate
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
Engaged ,
Feb 15, 2017 Feb 15, 2017

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

Translate
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 ,
Feb 15, 2017 Feb 15, 2017
LATEST

Post your full, actual code, please.

Translate
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