This content has been marked as final.
Show 11 replies

1. Re: Math.round with checkbox for tax
gkaiseril Jul 4, 2008 8:49 AM (in response to Bill Lomax)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 Jul 4, 2008 11:13 AM (in response to Bill Lomax)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) Jul 6, 2008 1:24 AM (in response to Bill Lomax)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 Jul 7, 2008 10:21 AM (in response to Bill Lomax)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) Jul 8, 2008 3:18 AM (in response to Bill Lomax)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) Jul 8, 2008 3:19 AM (in response to Bill Lomax)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 Jul 8, 2008 6:57 AM (in response to Bill Lomax)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 Jul 11, 2008 9:51 AM (in response to Bill Lomax)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
(NeenuGeorge) Oct 9, 2008 1:29 AM (in response to Bill Lomax)Hi,
I have to validate a numeric field to enter only numbers of length upto 20.how can i achieve this?
Thanks,
Neenu 
10. Re: Math.round with checkbox for tax
gkaiseril Oct 9, 2008 6:22 AM (in response to Bill Lomax)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
(NeenuGeorge) Oct 9, 2008 9:08 PM (in response to Bill Lomax)Hi,
I am using livecycle designer.I would like to know how to limit the textfield entry also.please help..
Thanks,
Neenu