Expand my Community achievements bar.

Calculating/rounding numeric fields--Payperiod and Hourly

Avatar

Former Community Member

Problem #1

I have 4 objects that are linked together. Field (1) Other-dropdown (2) Salary-numericfield  (3) payPeriod-numericfield  (4) perHour-numericfield

-the Salary-numericfield uses the Other selection to calculate the Hourly pay & Pay period amounts.

  • if ( Other.rawValue == "Normal" )

          {

               payPeriod.rawValue = (salary.rawValue) / (26);

               perHour.rawValue = (salary.rawValue) / (2080);

          }

Now you know the basic outline of what I am trying to do.  My question is this; How do I get the payPeriod to populate based on the perHour displayed value?  When I say "face value" I mean this; the perHour numeric field automatically populates an answer that automatically rounds the perHour field displayed number to the .00 value if the answer needs it. example 30.038 ----> 30.04, but holds the original rawValue for other calculations,   now I need to take 30.04 and populate the payPeriod numerfield (30.04 * 80) not (30.038 * 80) which keeps happening. The Java Script above shows how I originally set this up but do to the rounding it does not always agree. I am open to restructuring the code. I have tried functions, and calculate event for the perHour field ie.. payPeriod.rawValue = (perHour.rawValue * 80), which doesnt work.  I have another example of the rounding problem I am having below.

( 30.04 * 2080) = $62,483.20  and (30.038 * 2080) = $62,479.04.  Any immediate answer is much appreciated.

Problem #2

I have a similar set up to the above code but with a new multiple. This multiple is a percentage numeric field called FTE. I will present the set up for your understanding. My question is; I need the FTE value to dictate the calucation that will occur and I would like to understand if this is correct? Also, with the solution to Problem #1, will I have to change the solution for Problem #2?

  • if (Other.rawValue == "Normal" )

     {

          var total = ( FTE.rawValue)

          {

               if (total > .24 )

                    payPeriod.rawValue = (salary.rawValue) / (26) * (FTE.rawValue);

                    perHour.rawValue = (salary.rawValue) / (2080) * (FTE.rawValue);

               if (total < .25 )

                    payPeriod.rawValue = (salary.rawValue) / (26);

                    perHour.rawValue = (salary.rawValue) / (2080);

          }

     }

3 Replies

Avatar

Former Community Member

I assume that the field is showing the rounded value and not the number used for calcs. If so try using the formattedValue instead of the rawValue property of your objects. This will give you what is shown (the data after the patterns have been applied).

paul

Avatar

Former Community Member

This was a semi-helpful answer. I used the object.formattedValue and it did not result in an answer at all.  I have and am looking into the whole object.formattedValue concept to assure myself that I am doing it correctly.  I have the salary object generating the perhour answer and then i would like to take the perHour answer and generate the payperiod answer, using the already rounded number (formattedValue, Display value etc..).  Could you write the code as this example

payPeriod.rawValue = (perHour.formattedValue) * (80);

let me know if this is right or not, cause it is not working.--Allen

Avatar

Former Community Member

The formattedValue is only useful if you applied a pattern to the field. You coudl always use the round function in Javascript to get the value that you want.

Paul