Expand my Community achievements bar.

Autopopulate Percentage box

Avatar

Level 2

Autopopulate Percentage box

I am trying to get a percentage box added to my form where the percentage difference between the old and new salary is populated based on the old and new bi-weekly salarys. This is a general idea of what I am looking for:

Old Bi-weekly Salary(entered by user)Annual Salary(Autopopulates biweekly salary *26)
New Bi-Weekly Salary(entered by user)Annual Salary(Autopopulates biweekly salary *26)Percentage Difference

(need to populate % diff based on difference between old and new salaries)

Can someone please help me to get this to work? I cant seem to get it to work without messing up my autopopulated annual payout field.

Thanks in advance

Misti

3 Replies

Avatar

Level 10

I always have to look up percentages...found a good page here on calculating percentage change: http://www.mathsisfun.com/numbers/percentage-change.html

So basically the new value divided by the old value times 100 then subtract 100.

Using FormCalc on the Calculate event of the field:

if (HasValue(newSalaryField) & HasValue(oldSalaryField)) then

((newSalaryField/oldSalaryField) * 100) - 100

endif

In the Display pattern for your field you want num{zz9'%'} and click the Allow Zero checkbox.
That should do the trick!

Avatar

Level 10

Hi,

First make sure that the percentage object is a numericField.

if we work on the basis that the objects are named "oldSalary" and "newSalary", then the following JavaScript in the calculate event of the percentage object should work:

// first check that neither salary object is null

if (oldSalary.rawValue != null && newSalary.rawValue != null)

{

     this.rawValue = (newSalary.rawValue - oldSalary.rawValue) / oldSalary.rawValue;

}

Then in the Object > Field palette, click on the Patterns button. There is a percentage display pattern, which you can select and then adjust to how many decimal places you want it display to.

Hope that works/helps,

Niall

It's like busses, you wait for ages and then two come along at the same time 

Avatar

Level 2

Oh my gosh!!! It worked!! Thank you so much for your help!!!!!

You made my day

Thanks,

Misti