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

EMPTY CELL=ZERO IN CALCULATIONS

New Here ,
Aug 20, 2018 Aug 20, 2018

I am new to calculations in Acrobat. I have a column of cells, some of which are calculated and some are entered manually. They are as follows:

CASH PRICE (is calculated as the sum of previous cells)
TAX (this amount is entered manually)
TOTAL CASH PRICE (is the sum of CASH PRICE and TAX)less:
CASH DOWN (this amount is entered manually)
TRADE VALUE (is calculated as the sum of previous cells)

BALANCE DUE (is calculated as TOTAL CASH PRICE - CASH DOWN - TRADE VALUE)

So, this is what I have for the BALANCE DUE cell, under 'Custom Calculation Script':

// Get first field value

var v1 = getField("TOTAL CASH PRICE").value;

// Get second field value

var v2 = getField("CASH DOWN").value;

// Get third field value

var v3 = getField("TRADE").value;

// Set this field value equal to the difference

  event.value = v1-v2-v3;

This works fine, as long as an amount (even "0") is entered in the TAX and/or CASH DOWN cells.

My question is, how do I get the BALANCE DUE cell to calculate correctly, whether an amount is entered or if the cell is left blank (cell left blank=0)

TOPICS
PDF forms
1.4K
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
1 ACCEPTED SOLUTION
Community Expert ,
Aug 20, 2018 Aug 20, 2018
LATEST

This is a classic example of an incorrect calculation order. Many people assume that fields calculate in the correct order automatically, or based on their location on the page, or their tab order. They do not. There's a separate list that determines in which order the fields are calculated. You can find it in Form Edit mode, under the More button (or under Other Tasks, depending on your version of Acrobat).

View solution in original post

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 ,
Aug 20, 2018 Aug 20, 2018

You need to explicitly convert each variable to a number, so that even an empty value will be zero.

You do it like this:

var v1 = Number(getField("TOTAL CASH PRICE").value);

And the same with the other two, and then it should work.

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
New Here ,
Aug 20, 2018 Aug 20, 2018

Maybe I have something else wrong? It is still not functioning as I would like. If I don't enter a value into either the TAX or CASH DOWN cells, my BALANCE DUE cell is not calculating correctly. This is what I have:

// Get first field value

var v1 = Number(getField("TOTAL CASH").value);

// Get second field value

var v2 = Number(getField("CASH DOWN").value);

// Get third field value

var v3 = Number(getField("TRADE").value);

// Set this field value equal to the difference

event.value = v1-v2-v3;

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 ,
Aug 20, 2018 Aug 20, 2018

Is the value of any of the other fields calculated as well? If so, check the Fields Calculation Order.

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
New Here ,
Aug 20, 2018 Aug 20, 2018

I don't know what you mean by this. I have tried changing the order of how things calculate, and I am not getting the results I'm after.IMG1.PNG

CASH PRICE -- is calculated as the sum of the previous cells.
BALANCE DUE does not add the last number entered ($6000) even though it has been calculated in the CASH PRICE cell -- which is the cell that the BALANCE DUE calculation uses.

If I enter a "0" in the cell following $6000, then the BALANCE DUE cell calculates correctly.

VALUE OF TRADE-IN -- is calculated as the sum of the previous cells ALSO
and it is causing the same outcome with the BALANCE DUE cell

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 ,
Aug 20, 2018 Aug 20, 2018
LATEST

This is a classic example of an incorrect calculation order. Many people assume that fields calculate in the correct order automatically, or based on their location on the page, or their tab order. They do not. There's a separate list that determines in which order the fields are calculated. You can find it in Form Edit mode, under the More button (or under Other Tasks, depending on your version of Acrobat).

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