11 Replies Latest reply on Oct 9, 2008 9:08 PM by (NeenuGeorge)

    Math.round with checkbox for tax

    Bill Lomax Level 1
      I have a form that needs to calculate sales tax. If it ships to California, then tax is applied.
      I have been attempting to cobble together a Boolean JavaScript in Acrobat v8 (on a Mac) using Math.round(). No luck, it always defaults to else. I have searched this forum, planetpdf, bought Padlova's Acrobat Forms book, and just have been stonewalled on this issue.

      I have a series of items that SubTotal - ItemTotal.1, ItemTotal.2, ItemTotal.3 using the simplified Value is menu.

      California tax is calculated with (Tax * SubTotal) * 0.0725, where Tax is a checkbox with a Mouseup value of 1. When the checkbox is active, the tax is added, otherwise the tax value is zero.

      As near as I can tell looking at the State Board of Equalizations tax tables, Acrobats default rounding is displaying the correct amount of tax.

      Is there any reason I shouldnt leave this as it stands, as opposed to more research into the correct syntax for Math.round() with a checkbox variable?
        • 1. Re: Math.round with checkbox for tax
          gkaiseril MVP & Adobe Community Professional
          There are 2 products to create forms, Acrobat and LiveCycle Desinger, which one are you using?

          For Acrobat, set the export value to the tax rate and in the calculation field only compute the tax if the "Tax" check box is not "Off".

          In LiveCycle Designer, set the checked value to the tax rate and the unchecked value to zero. Then you can always do the tax computation.

          The displayed value is rounded on 5 or above, so there should be no need for the Math.round() method.
          • 2. Re: Math.round with checkbox for tax
            Bill Lomax Level 1
            Thank you George,

            I'm on a Macintosh, so LiveCycle designer isn't an option. I watched a video lesson on Lynda.com where the instructor was demonstrating the differences between the two applications. I could see the LiveCycle advantage for code heavy PDFs.

            My Tax checkbox has an export value of 1, and is set to "Execute a menu item" on Mouse Up

            My Calculate script is:

            (Tax*SubTotal) * 0.0775 // 1 * subtotal * taxrate = answer, else it's zero

            And near as I can tell, it works perfectly. For such a simple task, it sure is easy to NOT get the expected result.
            • 3. Re: Math.round with checkbox for tax
              (Aandi_Inston) Level 1
              What is the legal requirement for rounding of partial cents of tax in
              California? Round up, round down, which way is half a cent rounded?
              You need this as your starting point for coding.

              Aandi Inston
              • 4. Re: Math.round with checkbox for tax
                Bill Lomax Level 1
                Hello Aandi,

                The State of California rounds up. At 7.75%, tax on $1.10 calculates to 0.08525 cents, and is rounded up to 9 cents. The link in California for the BOE is http://www.boe.ca.gov/sutax/streimsched.htm for anyone looking at this thread in the future.

                It appears that rounding up is Acrobat's default, so no more coding is necessary. Thanks for the observation, I'm hoping that this thread will help someone else overcome this stumbling block. Tax calculations are a common need in a form.
                • 5. Re: Math.round with checkbox for tax
                  (Aandi_Inston) Level 1
                  Interesting - but exactly the sort of thing a programmer hates. It
                  gives a huge table, but it doesn't give the exact rules needed to
                  actually write legal code.

                  There isn't a generic standard to use. In fact, in some states, the
                  rule changed. For example, in 2005, Ohio changed to "The computation
                  shall be carried out to three decimal places. If the result is a
                  fractional amount of a cent, the calculated tax shall be rounded to a
                  whole cent using a method that rounds up to the next cent whenever the
                  third decimal place is greater than four. A vendor may elect to
                  compute the tax due on a transaction on an item or an invoice basis."
                  Instead of "always rounding up in any case where the tax calculation
                  yielded any fractional amount over a whole cent".

                  But you say "rounds up". Let's test that with the table. $100 is a
                  good starting point. 7.75% of $100 is exactly $7.75, so no rounding is
                  needed. This matches the table, which says that amounts over $99.93
                  pay $7.75 tax. So, what about $99.93? Calculated exactly, 7.75% is
                  $7.744575. If this were simply rounded up, the tax would be $7.75.
                  This suggests it is actually rounded to the closest, and might be the
                  same as the new Ohio rule. Or some variation on it.

                  Interestingly, there is a California sales tax calculator on
                  http://www.csgnetwork.com/salestaxcalc.html, and it seems to match the
                  table. They do offer a JavaScript calculator for license, and given
                  that it runs to something like 60 lines of code, this may be worth
                  considering, as reimplementing it (without copying) sounds hard work.

                  Aandi Inston
                  • 6. Re: Math.round with checkbox for tax
                    (Aandi_Inston) Level 1
                    Also note the vital point that (allowing for state regulations) you
                    might calculate tax on each line item, or on the total. But you MUST
                    NOT calculate and display tax on each line item, then calculate tax on
                    the total. In this case you MUST keep a running total of tax. This is
                    often overlooked, but if not done you will have invoices that just
                    don't add up.

                    Aandi Inston
                    • 7. Re: Math.round with checkbox for tax
                      gkaiseril MVP & Adobe Community Professional
                      California is not very clear about how to calculate the sales tax, but if you under collect it you owe them the shortage and if you over collect the tax you pay them the overage. They win and you lose no matter how you calculate the tax.
                      • 8. Re: Math.round with checkbox for tax
                        Bill Lomax Level 1
                        I just called the California BOE, and the employee I talked to said that (sic), "...you round up or down from the next number." In other words, the numbers are calculated, and then truncated at three decimal places, and then rounded up from anything over 4. So... using Aandi's example, 7.744575 truncates to 7.744 and the final tax is $7.74; which matches the state's table. My advice to anyone dealing with taxes in any state is to get your questions answered in writing, and to file the written answer away in a safe place. Geo's correct, they do collect, no matter what.

                        Thanks for that sales tax calculator link Aandi, that will come in very handy in the future.
                        • 9. Re: Math.round with checkbox for tax

                          I have to validate a numeric field to enter only numbers of length upto 20.how can i achieve this?

                          • 10. Re: Math.round with checkbox for tax
                            gkaiseril MVP & Adobe Community Professional
                            You might want to start a new post. We will need to know what product you are using to create your form as there are 2 different programs provided by Adobe to do this, Acrobat and LiveCycle Designer, and the two programs do not share a common language.
                            • 11. Re: Math.round with checkbox for tax
                              Level 1

                              I am using livecycle designer.I would like to know how to limit the textfield entry also.please help..