You are viewing limited content. For full access, please sign in.

Question

Question

Currency difference

asked on November 8

I have two currency fields in Forms with thousands delimiter set. I am using below java script to calculate the percentage of change between those 2 amounts. It gives as NaN. How do I use javascript to calculate the percentage correctly?

   var num1 = $('.payrate input').val();   
    var num2 = $('.currentsalary input').val();     
    
    var result = (num1) - (num2);   
      
    result = result / num2;
    result = round(result);

 

Thanks

Priya

0 0

Replies

replied on November 8

If the fields are displaying with the thousands delimiter, then you need to remove the delimiter(s) when you retrieve the values otherwise it will be treated as text and not a number.

For example (with a comma delimiter),

$('.currentsalary input').val().replace(/,/g,"")

However, why don't you just use Calculations instead? You can use the built-in calculations to do the same math without requiring custom JavaScript.

0 0
replied on November 8

Thanks. I will convert to formulas.

 

Priya

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.