Hi,
I’ll try to explain the process with an example. Assuming that the original equation is: fieldname1+fieldname2, but the values of these fields can be a merge of texts and numbers. so, my recommendation in this case would be modify the equation as follows:
(function(){
var f1=fieldname1, f2=fieldname2;
if(!jQuery.isNumeric(f1)) f1 = f1.replace( /[^\d\.]/g, '').replace(/^\.+/, '').replace(/\.+$/, '');
if(!jQuery.isNumeric(f2)) f2 = f2.replace( /[^\d\.]/g, '').replace(/^\.+/, '').replace(/\.+$/, '');
return f1*1+f2*1;
})()
Best regards.
Hi,
Thanks for the reply, just one more. Is it possible to add a shortcode inside the calculated fields form?
Thanks,
Rey
Hi @reyanntee,
I’m sorry, but that is not possible, the “Calculated Fields Form” plugin does not allow to include shortcodes of third-party plugins because we cannot controlling the tags, or javascript code included by the other plugins as replacements of their shortcodes, and most of them break our forms structures.
Best regards.
Hi,
how do i round off the return value into 2 decimal places?
this is what i am using at the moment
(function(){
var f1=fieldname4, f2=fieldname77, f3=fieldname3, f4=fieldname6, f5=fieldname7;
if(!jQuery.isNumeric(f1)) f1 = f1.replace( /[^\d\.]/g, '').replace(/^\.+/, '').replace(/\.+$/, '');
if(!jQuery.isNumeric(f2)) f2 = f2.replace( /[^\d\.]/g, '').replace(/^\.+/, '').replace(/\.+$/, '');
return f1*1+f2*1+f3*1+f4*1+f5*1;
})()
Thanks,
Rey
-
This reply was modified 9 years, 5 months ago by
reyanntee.
-
This reply was modified 9 years, 5 months ago by
reyanntee.
Hi @reyanntee,
The solution is really simple, you should use the “PREC” operation:
PREC(X,Y) rounds the number X with Y decimal places.
So, the line of code:
return f1*1+f2*1+f3*1+f4*1+f5*1;
should be modified as follows:
return PREC(f1*1+f2*1+f3*1+f4*1+f5*1,2);
and that’s all.
Best regards.