
1. Re: subtract and divide in a single custom calc script
try67 Jun 18, 2013 1:24 PM (in response to glvmlss01)Is this the calculation script for Pay4? If so, what kind of value should it have? The percentage rise between the old and the new salaries?
So if the old salary was 80 and the new 90, it should be 12.5%?

2. Re: subtract and divide in a single custom calc script
glvmlss01 Jun 18, 2013 1:40 PM (in response to try67)Yes, this is the script in Pay4. We want the value to be a precentage of the new rate versus the old rate. So if an employee received an increase from 80 to 90 it should be 12.5%.
With the script listed above it shows the precent as 11.1%

3. Re: subtract and divide in a single custom calc script
try67 Jun 18, 2013 1:46 PM (in response to glvmlss01)That's because you need to divide the new salary by the old one, not the other way around.
I believe this code should work correctly:
var P1 = Number(this.getField("Pay1").value);
var P2 = Number(this.getField("Pay2").value);
if (P1==0  P2==0) {event.value = ""}
else event.value = ((P2/P1)1)*100;

4. Re: subtract and divide in a single custom calc script
glvmlss01 Jun 18, 2013 1:53 PM (in response to try67)Thank you!!! this worked. The only other question I had was now it shows as 1,250.00%. I have my format set to precent and I chose 1 decimal place. Is there anything I can add to the scrpit or change to make it as just the precent with no commas? Hope that make sense.

5. Re: subtract and divide in a single custom calc script
try67 Jun 18, 2013 1:55 PM (in response to glvmlss01)1 person found this helpfulRemove the part that multiplies it by 100 from the code...
The thousands separator can be set via the Format tab.

6. Re: subtract and divide in a single custom calc script
glvmlss01 Jun 18, 2013 2:04 PM (in response to try67)Thanks again for all your help.

7. Re: subtract and divide in a single custom calc script
gkaiseril Jun 18, 2013 2:15 PM (in response to glvmlss01)Just compute the difference and divide by the starting pay value:
var P1 = Number(this.getField("Pay1").value); // starting base pay;
var P2 = Number(this.getField("Pay2").value); // ending pay;
event.value = 0; // clear the field
if(P1 != 0 & P2 != 0) {
// only compute if divisor is nonzero and there is an ending pay value;
event.value = (P2  P1) / P1; // decimal change in pay rate from base pay;
}
Use parenthesis to set the calculation order.