Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 4 123 ... LastLast
Results 1 to 15 of 50
  1. #1
    New Coder
    Join Date
    May 2012
    Posts
    27
    Thanks
    5
    Thanked 0 Times in 0 Posts

    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.
    Last edited by wwilson80; 05-26-2012 at 11:19 PM.

  • #2
    Regular Coder
    Join Date
    Apr 2012
    Posts
    165
    Thanks
    1
    Thanked 39 Times in 39 Posts
    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
    Last edited by EpicWebDesign; 05-26-2012 at 11:44 PM.

  • #3
    New Coder
    Join Date
    May 2012
    Posts
    27
    Thanks
    5
    Thanked 0 Times in 0 Posts

    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.

  • #4
    Regular Coder
    Join Date
    Apr 2012
    Posts
    165
    Thanks
    1
    Thanked 39 Times in 39 Posts
    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.

  • #5
    New Coder
    Join Date
    May 2012
    Posts
    27
    Thanks
    5
    Thanked 0 Times in 0 Posts

    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

    Thank you for your help

  • #6
    Regular Coder
    Join Date
    Apr 2012
    Posts
    165
    Thanks
    1
    Thanked 39 Times in 39 Posts
    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;

  • #7
    New Coder
    Join Date
    May 2012
    Posts
    27
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Syntax Error

    I get a syntax error on the second line of code

  • #8
    Regular Coder
    Join Date
    Apr 2012
    Posts
    165
    Thanks
    1
    Thanked 39 Times in 39 Posts
    On the result=math... line?

    Please forgive my slow answers... I'm posting from my phone
    Last edited by EpicWebDesign; 05-27-2012 at 12:54 AM.

  • #9
    New Coder
    Join Date
    May 2012
    Posts
    27
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Line error

    Yes in the math.round line

  • #10
    Regular Coder
    Join Date
    Apr 2012
    Posts
    165
    Thanks
    1
    Thanked 39 Times in 39 Posts
    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?

  • #11
    New Coder
    Join Date
    May 2012
    Posts
    27
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Syntax Error

    It still gives a syntax error

  • #12
    Regular Coder
    Join Date
    Apr 2012
    Posts
    165
    Thanks
    1
    Thanked 39 Times in 39 Posts
    Quote Originally Posted by wwilson80 View Post
    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.

  • #13
    New Coder
    Join Date
    May 2012
    Posts
    27
    Thanks
    5
    Thanked 0 Times in 0 Posts
    It always returns a syntax error when using the round.math function

  • #14
    Regular Coder
    Join Date
    Apr 2012
    Posts
    165
    Thanks
    1
    Thanked 39 Times in 39 Posts
    Oh... ok. I was not aware of that until now. What version of Adobe are you using?

  • #15
    New Coder
    Join Date
    May 2012
    Posts
    27
    Thanks
    5
    Thanked 0 Times in 0 Posts
    Acrobat 9 Professional


  •  
    Page 1 of 4 123 ... LastLast

    Posting Permissions

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