Return negative number as 0
-
Hi, first time posting so hopefully doing it correctly. I have used a form builder to build my forms but have run into a couple of issues with functionality. In the code/calculation below I need to be able to return the answer 0 if the answer is less than 0. I've searched loads to no avail so any help would be much appreciated. T.I.A.
$('form#Commission #Commission_On').formCalc(" Nett_Earnings -Actual_Takings >0==0",{ currency_format:true, mirror:'sfm_Commission_On_parsed'});
-
Hi, first time posting so hopefully doing it correctly. I have used a form builder to build my forms but have run into a couple of issues with functionality. In the code/calculation below I need to be able to return the answer 0 if the answer is less than 0. I've searched loads to no avail so any help would be much appreciated. T.I.A.
$('form#Commission #Commission_On').formCalc(" Nett_Earnings -Actual_Takings >0==0",{ currency_format:true, mirror:'sfm_Commission_On_parsed'});
You still have the same problem that the expression
Nett_Earnings -Actual_Takings >0==0
does not make a lot of sense. The>
operator means greater than, and==
means equals. You need to capture the value ofNett_Earnings -Actual_Takings
and then set it to zero if it is negative (assuming I understand the question). -
You still have the same problem that the expression
Nett_Earnings -Actual_Takings >0==0
does not make a lot of sense. The>
operator means greater than, and==
means equals. You need to capture the value ofNett_Earnings -Actual_Takings
and then set it to zero if it is negative (assuming I understand the question). -
Thanks for replying. I'm struggling to get to the point of showing 0. Is this more like what I should have Nett_Earnings-Actual_Takings=Value<0=0 Does the script generate Value?
No, that is still not a valid expression. I think you need to do one or both of two things: 1. Learn Javascript, expecially with regard to expressions and operators. 2. Find out exactly how this package that you are trying to use actually works. It may well be that it uses different syntax from Javascript so anything mentioned here may not be valid.
-
Hi, first time posting so hopefully doing it correctly. I have used a form builder to build my forms but have run into a couple of issues with functionality. In the code/calculation below I need to be able to return the answer 0 if the answer is less than 0. I've searched loads to no avail so any help would be much appreciated. T.I.A.
$('form#Commission #Commission_On').formCalc(" Nett_Earnings -Actual_Takings >0==0",{ currency_format:true, mirror:'sfm_Commission_On_parsed'});
Looking at the documentation, you need to modify your calculation to use either an
if_else
expression:$('form#Commission #Commission_On').formCalc("if_else(Nett_Earnings > Actual_Takings, Nett_Earnings - Actual_Takings, 0)", { currency_format:true, mirror:'sfm_Commission_On_parsed' });
or the
max
function:$('form#Commission #Commission_On').formCalc("max(Nett_Earnings - Actual_Takings, 0)", { currency_format:true, mirror:'sfm_Commission_On_parsed' });
Calculation field : function reference| Simfatic Forms 5.0 Help[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
-
Looking at the documentation, you need to modify your calculation to use either an
if_else
expression:$('form#Commission #Commission_On').formCalc("if_else(Nett_Earnings > Actual_Takings, Nett_Earnings - Actual_Takings, 0)", { currency_format:true, mirror:'sfm_Commission_On_parsed' });
or the
max
function:$('form#Commission #Commission_On').formCalc("max(Nett_Earnings - Actual_Takings, 0)", { currency_format:true, mirror:'sfm_Commission_On_parsed' });
Calculation field : function reference| Simfatic Forms 5.0 Help[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer