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

    (@codepeople)

    Hello @fifiburleigh,

    Assuming there are six number fields in the form: fieldname1, fieldname2, fieldname3, fieldname4, fieldname5 and fieldname6, and you want calculate the sum of their values, and finally round the result to obtain an integer number as result. The equation associated to the calculated field would be:

    ROUND(fieldname1+fieldname2+fieldname3+fieldname4+fieldname5+fieldname6)

    If you want get only the integer part of the sum (without rounding):

    FLOOR(fieldname1+fieldname2+fieldname3+fieldname4+fieldname5+fieldname6)

    If you want get the integer number greater than or equal to the result:

    CEIL(fieldname1+fieldname2+fieldname3+fieldname4+fieldname5+fieldname6)

    Finally, if you want the result include a specific number of decimals, use the “PREC” operation: PREC(X, Y) returns the number X rounded with Y decimal places.

    In the previous equation if you want get the result with two decimal places:

    PREC(fieldname1+fieldname2+fieldname3+fieldname4+fieldname5+fieldname6,2)

    and that’s all.
    Best regards.

    Thread Starter fifiburleigh

    (@fifiburleigh)

    Thank you that’s awesome! So then how do I get the integer number to reduce to one single digit if it’s double or triple digits? I would have to somehow command it to add the integer digits together for a final single digit.

    Plugin Author codepeople

    (@codepeople)

    Hello,

    It is pure mathematics, if you want only the last digit of an integer number, the solution is:

    – Convert the number in integer (FLOOR(X))
    – Get the rest of division by 10 (number%10)

    and that’s all.

    For example, if the operation is: fieldname1+fieldname2

    edit it as follows:

    FLOOR(fieldname1+fieldname2)%10

    Best regards.

    Thread Starter fifiburleigh

    (@fifiburleigh)

    Thanks for your help, much appreciated!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Total and reduce to single digit’ is closed to new replies.