# WordPress.org

## Calculated Fields Form[resolved] IF Calculation (2 posts)

1. markharkin
Member
Posted 3 years ago #

Hi
Firstly thanks for such an amazing plugin! and i am wondering if you could help me.

I want to calculate a formula in relation to what a user inputs for example.

If fieldname2 is < 1000 I would like to calculate prec((fieldname5-fieldname4)*(fieldname2*0.08/365),2)+fieldname2+40

If fieldname2 is => 1000 but <10000 I would like to calculate prec((fieldname5-fieldname4)*(fieldname2*0.08/365),2)+fieldname2+70

If fieldname2 is =10000 1000 I would like to calculate prec((fieldname5-fieldname4)*(fieldname2*0.08/365),2)+fieldname2+100

Is this possible?

Thanks
Mark

2. codepeople
Member
Plugin Author

Posted 3 years ago #

Hi,

Yes, that's possible, the calculated field is very powerful and let you use a snippet of Javascript code if you require of a complex equation:

Please, use the code below as equation associated to your calculated field:

(function(){
if(fieldname2 < 1000){
return prec((fieldname5-fieldname4)*(fieldname2*0.08/365),2)+fieldname2+40;
}else if(fieldname2 >= 1000 && fieldname2 < 10000 ){
return prec((fieldname5-fieldname4)*(fieldname2*0.08/365),2)+fieldname2+70;
}else if(fieldname2 == 10000){
return prec((fieldname5-fieldname4)*(fieldname2*0.08/365),2)+fieldname2+100;
}
})()

This topic has been closed to new replies.