Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.

1. ## Javascript Math Calculation in Adobe PDF

I am trying to change a number in a calculation in a PDF document. The number comes out to 8000.536 I need the number to be 8000.54. I have the number format set to 2 decimal places. I have tried the round function and it does not seem to work. I have a field called CPP which is a inputted whole number. The second field is called Deposit which is a calculated field as follows CPP * .25 the next field is called Balance which is a calculation of CPP - Deposit but depending on the amount in CPP the return calculation is off .01 which is because the Deposit field is not rounded off. How can I correct this please.

• Can you post your code? The math.round function should work.

for example:
Code:
```var myNum=8000.536

var result=Math.round(myNum*100)/100```
that should return 8000.54

• ## Code I am using

var myNum=this.getField("Deposit")
var result=Math.round(myNum*100)/100;
CPP - result

The field that this code is in is called Balance_Due. If I use the fields CPP - Deposit I am always off .01.

• Please post the whole code (JS & form). From what you posted, CPP has not been assigned a value. If I can see the whole code I can try to help you figure out where the disconnect is.

• ## More Code

The CPP field code is an addition function as follows:
RS3\$, Sales_Tax, Subtotal

The Deposit field code is as follows:
CPP * .25

• I'm assuming you are using custom calculations. Have you tried specifying the fields are numeric? See if this makes any difference? You might need to do the same thing for the CPP field.
Code:
```var myNum=Number(this.getField("Deposit").value);
var result=Math.round(myNum*100)/100;
event.value = CPP - result;```

• ## Syntax Error

I get a syntax error on the second line of code

• On the result=math... line?

• ## Line error

Yes in the math.round line

• Ok, but this didn't occur when you didn't specify it as numeric, correct? i.e.,

```var myNum=this.getField("Deposit") var result=Math.round(myNum*100)/100;```

have you tried doing ONLY that function (without the event.value =CPP-results)? Does it round correctly?

• ## Syntax Error

It still gives a syntax error

• Originally Posted by wwilson80
var myNum=this.getField("Deposit")
var result=Math.round(myNum*100)/100;
CPP - result

The field that this code is in is called Balance_Due. If I use the fields CPP - Deposit I am always off .01.
Sorry, I thought you said you were using the code above but it simply wasn't rounding off the numbers correctly. Has it been returning a syntax error the entire time? You hadn't mentioned that until now. I'm just trying to narrow down where the problem lies.

• It always returns a syntax error when using the round.math function

• Oh... ok. I was not aware of that until now. What version of Adobe are you using?

• Acrobat 9 Professional

•
Page 1 of 4 123 ... Last

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•