Skip to main content
jacik062107
Participant
September 7, 2016
Question

I need help rounding a field up to the nearest 10,000

  • September 7, 2016
  • 2 replies
  • 293 views

I have a form I created in excel and created it in Adobe. One of the fields needs to be calculated by rounding up the Annual Salary (another calculated field) to the nearest $10,000. I'm not familiar with Java Script, so I haven't been able to find just the right type of code to put in place.

Any help would be much appreciated.

Thank you!!! Jaci

This topic is closed to new replies. Start a new post to keep the conversation going.

2 replies

try67
Community Expert
Community Expert
September 7, 2016

You can use this code as the custom calculation script of your field:

var salary = Number(this.getField("Annual Salary").value);

event.value = roundUpTo(salary, 10000);

function roundUpTo(n, target) {

    if (n%target==0) return n;

    return n+(target-(n%target));  

}

jacik062107
Participant
September 7, 2016

That worked perfectly! I had to change the 10000 to 1000, because I was off on the round to amount, but the code worked great!

Thank you!!