• Resolved reyanntee

    (@reyanntee)


    Hi, Just wanted to ask also how to ignore text value on the calculated field input.

    What i want to know is how to ignore text data if the formula of the calculated field input is the sum of different fields, so it would only add the number values and ignore the text information.

    Thanks,
    Rey

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author codepeople

    (@codepeople)

    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.

    Thread Starter reyanntee

    (@reyanntee)

    Hi,

    Thanks for the reply, just one more. Is it possible to add a shortcode inside the calculated fields form?

    Thanks,
    Rey

    Plugin Author codepeople

    (@codepeople)

    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.

    Thread Starter reyanntee

    (@reyanntee)

    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 8 years, 5 months ago by reyanntee.
    • This reply was modified 8 years, 5 months ago by reyanntee.
    Plugin Author codepeople

    (@codepeople)

    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.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Need help on ignoring text data’ is closed to new replies.