• Resolved stevedawsonuk

    (@stevedawsonuk)


    Is there a way to round up or down to the closest 0.5 so that…

    ROUND(3.25) returns 3
    ROUND(3.26) returns 3.5
    ROUND(3.49) returns 3.5
    ROUND(3.50) returns 3.5
    ROUND(3.51) returns 4

    Thanks in advance

    Steve

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

    (@codepeople)

    Hello @stevedawsonuk

    Thank you very much for using our plugin. Yes, that’s possible. In this case, you must pass 0.5 as the second parameter of the ROUND operation:

    ROUND(3.24, 0.5) returns 3.0
    ROUND(3.26, 0.5) returns 3.5
    ROUND(3.49, 0.5) returns 3.5
    ROUND(3.50, 0.5) returns 3.5
    ROUND(3.51, 0.5) returns 3.5

    Note that 3.51 is nearest to 3.5 than 4

    Best regards.

    Thread Starter stevedawsonuk

    (@stevedawsonuk)

    Thanks for the speedy reply, my apologies, I was not clear enough in my explanation.

    In my examples the values are from variables that the end user types into 2 fields and the results are from a calculated field where I currently have this…

    fieldname5*fieldname3/1.2

    Plugin Author codepeople

    (@codepeople)

    Hello @stevedawsonuk

    The solution would be similar:

    ROUND(fieldname5*fieldname3/1.2, 0.5)

    Best regards.

    Thread Starter stevedawsonuk

    (@stevedawsonuk)

    Thanks for that, is there any way to achieve rounding up or down to the nearest 0.5... like this

    ROUND(3.00) returns 3
    ROUND(3.01) returns 3
    ROUND(3.02) returns 3
    ROUND(3.03) returns 3
    ROUND(3.04) returns 3
    ROUND(3.05) returns 3
    ROUND(3.06) returns 3
    ROUND(3.07) returns 3
    ROUND(3.08) returns 3
    ROUND(3.09) returns 3
    ROUND(3.10) returns 3
    ROUND(3.11) returns 3
    ROUND(3.12) returns 3
    ROUND(3.13) returns 3
    ROUND(3.14) returns 3
    ROUND(3.15) returns 3
    ROUND(3.16) returns 3
    ROUND(3.17) returns 3
    ROUND(3.18) returns 3
    ROUND(3.19) returns 3
    ROUND(3.20) returns 3
    ROUND(3.21) returns 3
    ROUND(3.22) returns 3
    ROUND(3.23) returns 3
    ROUND(3.24) returns 3
    ROUND(3.25) returns 3
    ROUND(3.26) returns 3.5
    ROUND(3.27) returns 3.5
    ROUND(3.28) returns 3.5
    ROUND(3.29) returns 3.5
    ROUND(3.30) returns 3.5
    ROUND(3.31) returns 3.5
    ROUND(3.32) returns 3.5
    ROUND(3.33) returns 3.5
    ROUND(3.34) returns 3.5
    ROUND(3.35) returns 3.5
    ROUND(3.36) returns 3.5
    ROUND(3.37) returns 3.5
    ROUND(3.38) returns 3.5
    ROUND(3.39) returns 3.5
    ROUND(3.40) returns 3.5
    ROUND(3.41) returns 3.5
    ROUND(3.42) returns 3.5
    ROUND(3.43) returns 3.5
    ROUND(3.44) returns 3.5
    ROUND(3.45) returns 3.5
    ROUND(3.46) returns 3.5
    ROUND(3.47) returns 3.5
    ROUND(3.48) returns 3.5
    ROUND(3.49) returns 3.5
    ROUND(3.50) returns 3.5
    ROUND(3.51) returns 4
    ROUND(3.52) returns 4 etc



    Plugin Author codepeople

    (@codepeople)

    Hello @stevedawsonuk

    You need a custom rounding operation. So, you can implement the equation as follows:

    (function(){
    var n = fieldname5*fieldname3/1.2,
    i = FLOOR(n),
    d = n-i;
    
    if(d <= 0.25) return i;
    if(d <= 0.5) return i+0.5;
    return i+1;
    })()

    Best regards.

    Thread Starter stevedawsonuk

    (@stevedawsonuk)

    I just wanted to take a moment to congratulate you on your outstanding product and evenincredible support. Genuinely 10/10 *****

    Thank you for your help with this, I will certainly be recommending your product and will be making a tutorial for my YouTube channel later today to share with my audience.

    Best Regards

    Steve

    Plugin Author codepeople

    (@codepeople)

    Hello @stevedawsonuk

    Thank you, thank you very much.

    Best regards.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Round Up or Down to nearest 0.5’ is closed to new replies.