• Resolved mahakaal28

    (@mahakaal28)


    Hello,
    I am trying to achieve the below form. Could it be possible to do in cff.

    Fieldname1 = single line text. User should be able to enter series of numbers (for eg: 1, 2, 3, 7, 9)

    Fieldname2 = calculated field. It will count the numbers entered in fieldname1.

    Fieldname3 = calculated field. It will add the numbers in fieldname1.

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

    (@codepeople)

    Hello @mahakaal28

    Yes, that’s possible. Please, enter the following equation in the fieldname3 field:

    (function(){
    var v = fieldname1|r;
    v = (new String(v)).replace(/[^\d\.\,]/g, '').replace(/\,+/g, ',');
    return AVERAGE(v.split(','));
    })()

    Best regards.

    Thread Starter mahakaal28

    (@mahakaal28)

    I also want to show the numbers count in fieldname2.

    Plugin Author codepeople

    (@codepeople)

    Hello @mahakaal28

    In this case, the equation can be edited as follows:

    (function(){
    var v = fieldname1|r;
    v = (new String(v)).replace(/[^\d\.\,]/g, '').replace(/\,+/g, ',');
    var n = v.split(',');
    return 'Average: '+AVERAGE(v.split(','))+' count: '+n.length;
    })()

    Best regards.

    Thread Starter mahakaal28

    (@mahakaal28)

    Will it be possible, from enter values in fieldname1.

    {(1²+ 2²+ 3²+ 7²+ 9²) – ((1+2+3+7+9)²/count)} / (count-1)

    Plugin Author codepeople

    (@codepeople)

    Hello @mahakaal28

    In the new case, the equation would be similar to:

    (function(){
    var v = fieldname1|r;
    v = (new String(v)).replace(/[^\d\.\,]/g, '').replace(/\,+/g, ',');
    var n = v.split(','), 
        count = n.length,
        a = 0,
        b = 0;
    for(var i in n)
    {
    a += POW(n[i], 2);
    b += n[i]*1
    }
    return (a - (POW(b, 2)/count)) / (count-1);
    })()

    Best regards.

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Average’ is closed to new replies.