How to get Percentage value

Supriya25
Tera Guru

Hi,

Through Business rule i am getting right Percentage , but client wants onChange

find_real_file.png

Total Revenue of Project ( $ ) - field Integer type

Project Profitability ( $ ) - field Integer type

Formula : (U-R)/U

var projectrevenue = g_form.getValue('u_total_revenue_per_milestone'); //U//
var projectcost = g_form.getValue('u_project_profitability'); //R//
var percentage=(projectrevenue -projectcost )/projectrevenue 
 var percentagevalue = percentage * 100;
 alert('percentage :'+percentagevalue);
 g_form.setValue('u_gpm', percentagevalue.toFixed(2));

1 ACCEPTED SOLUTION

Try below.

var projectrevenue = g_form.getValue('u_total_revenue_per_milestone').replace(/,/g,'')); //U//
var projectcost = g_form.getValue('u_project_profitability').replace(/,/g,'')); //R//
var pr = parseFloat(projectrevenue);
var pc =parseFloat(projectcost);
alert(pr + "---" + pc);

var percentage = pr - pc;

alert(percentage);
var uu = percentage / pr;
alert(uu);
var percentagevalue = parseFloat(percentage * 100);
alert('percentage :' + percentagevalue);
g_form.setValue('u_gpm', percentagevalue.toFixed(2));

View solution in original post

18 REPLIES 18

Hi Jaspal,

your script is working fine,Thanks for script.

can you tell me .replace(/,/g,'')); what will do here.?

So, when you used parseFloat() it ignored the text after ',' (comma).

Using .replace(/,/g,''));  will ensure that 201,450 is considered as 201450.

In short it replaces , (comma) with nothing.

do we have this  .replace(/,/g,''));  at javascript side

.replace() yes it is. Did you try it with code above? If not try & check for difference.

Sorry for delay reply.

can you help me what is the meaning of (/,/g,'')