8 Replies Latest reply on May 1, 2013 1:22 PM by Docmhz

    Multiply two fields then divide

    Docmhz

      Hello,

       

      I need to get the sum of two fields and then divide that by 100 on a form I've created. I'm new to this, so any help is much appreciated!

       

       

        • 1. Re: Multiply two fields then divide
          gkaiseril MVP & Adobe Community Professional

          Programming is in the details.

           

          how-to-do-not-so-simple-form-calculations by Thom Parker.

           

          Without the exact field names it is pretty hard to provide much help.

          • 2. Re: Multiply two fields then divide
            Docmhz Level 1

            I thought the Simplified field would work for me, but it doesn't do what I think it should do.

             

            I need to multiply a field names "Line3xLine4" and a field named "DiscountFactor" and have that sum divided by 100.

             

            I tried the Simplified field and this is what I came up with:

             

            (Line2xLine4*DiscountFactor)/100

             

            This gives me a 0 as an answer.

             

            Thanks again for the help!

            • 3. Re: Multiply two fields then divide
              gkaiseril MVP & Adobe Community Professional

              White space is used to parse the field name, operands, and constants in the Simplified Field Notation. It also makes reading the code easier.

               

              Are you getting any errors in the JavaScript console?

               

              Also field formatting is important. If you "DiscountFactor" is formatted as a percentage and you have correct percentage value displaying do not divide by 100. The decimal place of the field has already been adjusted for calculations.

              • 4. Re: Multiply two fields then divide
                Docmhz Level 1

                I'm not getting any errors, and I do not have the Discount Factor field formatted other than for 2 decimal places.

                 

                I need to either be able to divide the sum by 100 to make it an accurate $ number or be able to multiply "Line3xLine4" by "DiscountFactor" as a percentage. The users will enter the "DiscountFactor" field as a whole number, i.e. 97.5%.

                 

                Is there any easier way to do this?

                 

                Thanks

                • 5. Re: Multiply two fields then divide
                  gkaiseril MVP & Adobe Community Professional

                  There could be other issues since all fields with calculations interact with each other it is hard to see if there are other problems with your form.

                   

                  Is the field order for the calculations correct?

                   

                  What happens when additional data is added to the form?

                   

                  Do you get the expected results?

                   

                  Do you get the result expected before the additional data was added?

                  • 6. Re: Multiply two fields then divide
                    Docmhz Level 1

                    I can get the form to calculate properly if the user enters the percentage as a decimal. However, I will have hundreds of users and cannot rely on that being the case every time. So I need to be able to divide by 100 or somehow manipulate the number the users enter into a decimal value i.e. 97.5% = .975.

                     

                    Thanks

                    • 7. Re: Multiply two fields then divide
                      gkaiseril MVP & Adobe Community Professional

                      Well this is how Acrobat forms work.

                       

                      If you want to have work differently, then you will have a lot of scripting for keystroke, formatting and calculations. Add the "%" sign to a value makes the value a string and not a number. The one exception is when it is added as a format item only.

                       

                      You can use the "validate" tab to limit the range of values that can be entered and issue an warning and provide instructions on how to enter a percentage as a decimal number. This is just like using a 10 key adding machine and not using the "%" key.

                      • 8. Re: Multiply two fields then divide
                        Docmhz Level 1

                        They wouldn't be using the % sign, just entering 97.5 etc... Going down the validation route, how do I make it validate starting with a decimal? .975 for example?

                         

                        Thanks for all the tips.