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

Rounding up

clarioncall
Registered: May 12 2008
Posts: 4

I need the script to produce a number which includes the following steps:
1. Take a number from one field in the document, rounded up to the nearest 100
2. Multiply that figure by 15
3. Divide that figure by 100

My Product Information:
Acrobat Pro 7.0.8, Windows
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4308
// Document level scripts
function Round(sInput) {
// return input as integer from round inputted number formatted to 3 decimals
var fNumber = Number(sInput); // force to number
var sNumberD2 = util.printf('%0 .2f', fNumber); // force to 2 rounded decimal place string - adjust of level of rounding desired
var fNumberD2 = Number(sNumberD2); // force back to number
return Math.round(fNumberD2); // round to whole number
}

function RoundNearest(sInput, sDecimal) {
/*
Round to nearest passed decimal value
Divide by passed Decimal value to obtain number of Decimals of the number
Round converted input to whole number
Multiply by Decimal to return to nearest whole decimal value
*/
var fInput = Number(sInput); // convert to number
var fDecimal = Number(sDecimal); // convert number
if (fDecimal == 0) { // test for divide by zero
app.alert('sDecimal must be a number! ' + sDecimal, 0, 1);
return ''; // force exit
}
var fNumber = fInput / fDecimal; // convert to units of sDecimal for rounding
var fRound = Round(fNumber); // round to whole numbers
return (fRound * fDecimal); // return in whole decimal units
} // end function RoundNearest
// end document level scripts

// custom field calculation script
var fHundreths = RoundNearest(this.getField('Input').value, 100); // round to nearest 100th
event.value = fHundreths * 15 / 100; // compute based on neared hundredths

George Kaiser

clarioncall
Registered: May 12 2008
Posts: 4
Thank you so much! I really do appreciate it.