These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Acrobat form and taxes, rounding decimals and calculating

lajj
Registered: Jul 30 2008
Posts: 13

hi.
I have a document that I need to tiddy up.
Here is the picture:

I have, in the first block, a couple of fields to be calculated (hon.0, hon.1 hon.3, etc), and the result to be returned in a field (named stot.0), wich will be taxable:
var f = this.getField("hon");
var a = f.getArray();
var sum = 0;
for (i =0; i < a.length; i++)
sum += a[i].value;
event.value = sum * 1;

This works fine.

Then another block of fields (deb.0, deb.1, deb.2, etc) to be calculated, and the result to be returned in a field named stot.1 (also taxable):
var f = this.getField("deb");
var a = f.getArray();
var sum1 = 0;
for (i =0; i < a.length; i++)
sum1 += a[i].value;
event.value = sum1 * 1;

Then this field (soustotal.0) calculate the sum of those 2 fields:
var f = this.getField("stot");
var a = f.getArray();
var sum4 = 0;
for (i =0; i < a.length; i++)
sum4 += a[i].value;
event.value = sum4 * 1;

This works fine also.

Then I have this block of fields to be calculated (debnt.0, debnt.1, etc), and the result to be returned in a field, named "montdebont" (but not taxable, will be added to the total):
var f = this.getField("debnt");
var a = f.getArray();
var sum3 = 0;
for (i =0; i < a.length; i++)
sum3 += a[i].value;
event.value = sum3 * 1;

At this point, all is good and tight.

BUT:
My problems starts with the first tax field:
var f = this.getField("soustotal.0");
event.value = Math.round(f.value * 0.05);

The numbers showing in this field need to be rounded to 2 decimals. and nothing is working, the result is always rounded to NO decimal at all.

After that I have to add another tax on the result of the first tax and the "soustotal"
Then add the content of the "montdebont" field to the result of the taxed soustotal.

Anyways, since my english is quite poor here is the file http://drop.io/zhedvgd#

Many thanks for any input, help or pointing in the right direction.

gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4307
The JavaScript 'Math.round()' method rounds to the nearest integer. See [url=http://www.acrobatusers.com/forums/aucbb/viewtopic.php?id=20791]Multiplication Rounding up[/url] for a long post that discusses this issue and provides coding for setting up a document level function with which one can specify the number of decimal places to round to.

George Kaiser