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

Sum and Multiply by tax rateq

fbfcwi
Registered: Mar 24 2010
Posts: 4
Answered

Hi,

I'm trying to have a field that calculates the tax amount on four other fields and adds them. I want this rounded to two decimal points. Does anyone have a code/script that could help me with this? I have:
Code:
event.value = 0;
event.value = Math.round(this.getField("Amount-1").value * .051)+Math.round(this.getField("Amount-2").value * .051)+Math.round(this.getField("Amount-3").value * .051)+Math.round(this.getField("Amount-4").value * .051)
But I don't want it to round...

Thanks!
Dawn

My Product Information:
Acrobat Pro 9.0, Windows
gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4308
And how are you expecting the 'Math.round()' method to work?

There is only one parameter so one can not specify any decimal level.

[url=https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Math/round]MDC Math.round method[/url]. So you are rounding each of your individually computed values to the nearest integer. And this in not what you want to do. If you adjust for the decimal point, there are still some issues with using the 'Math,round()' method.

One can use the Acrobat 'uti.printf()' method to obtain a more consistent rounding of a number. And since you are going to repeat this code, I would create a function to run the piece of code that performs the rounding.
function Round(nValue, iDecimal) {// use the  util.printf method to round the nValue to iDecimal placesreturn Number( util.printf('%,1 .' + Math.floor(iDecimal) + 'f', Number(nValue) ) );} // end of Found function event.value = Round(this.getField("Amount-1").value * 0.51, 2) +Round(this.getField("Amount-2").value * 0.51, 2) +Round(this.getField("Amount-3").value * 0.51, 2) +Round(this.getField("Amount-4").value * 0.51, 2);

George Kaiser

fbfcwi
Registered: Mar 24 2010
Posts: 4
Thanks! That solves my problem!