• Resolved Toto146

    (@toto146)


    Hi there,

    using PREC((fieldname21*0.5),2) brings me a wrong result by rounding wrong.

    E.G.: 150,55 * 0,5 = 72,275 -> Result from CFF 72,27. But I need it to round up from 5 to 9.

    Thanks for your help

    Thorsten

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

    (@codepeople)

    Hello @toto146,

    You can use the following operation instead:

    PREC(ROUND(fieldname21*0.5,0.01),2)

    PREC(fieldname21*0.5, 2) is quivalent to the javascript code: (fieldname21*0.5).toFixed(2)

    Best regards.

    Thread Starter Toto146

    (@toto146)

    Hello @codepeople,

    thanks for your fast reply. I’ve tried the new formula but now the result for the example in the opening thread

    What I need is the correct round like in this example:

    161,95€ * 0,5 = 80,975€ -> cff rounds down to 80,97€ -< I need the correct rounding to 80,98€

    Using the new formula makes out of 161,95€ * 0,5 = 81,00€.

    What can I do?

    Kind regards
    Thorsten

    Plugin Author codepeople

    (@codepeople)

    Hello @toto146,

    Are you sure that the equation was included using the second parameter in the ROUND operation?

    I’ve tested the equation with the structure I sent you in the previous ticket and the number 161.95, used in your example, and the result is 80.97

    Please, look the screenshot visiting the following link:

    https://wordpress.dwbooster.com/customdownloads/2018/07/13/screenshot_equation.png

    Best regards.

    Thread Starter Toto146

    (@toto146)

    Hello @codepeople,

    I’ve tried this in console also but my result you can see in the attachment. Crazy.

    Plugin Author codepeople

    (@codepeople)

    Hello @toto146,

    The second parameter of the “ROUND” operation was included in the latest updates of the plugin, so, I guess you are using a previous version of the plugin on your website. Please, update your copy of the plugin and try again.

    Best regards.

    Thread Starter Toto146

    (@toto146)

    Hello @codepeople ,

    now after an update the result from

    PREC(ROUND(161.95*0.5,0.01),2) is 80,97.

    But this is still not the result that I need.

    161,95 / 2 = 80,975 -> this must be rounded up to 80.98.

    Reaching a 5 should round up to the next full result. E.g. 20,255 = 20,26

    Thanks in advance,
    Thorsten

    Plugin Author codepeople

    (@codepeople)

    Hello @toto146,

    The operation: ROUND(80.975,0.01) is equivalent in basic javascript to:

    
    Math.round(80.975*100)/100 = 
    Math.round(8097.5)/100 = 8097/100 = 80.97
    

    as you can see, unfortunately the Javascript engine rounds the number 8097.5 as 8097 and not 8098

    The alternative is a simple trick:

    Modifies your operation as follows:

    
    PREC(ROUND(161.95*0.5+0.000000001,0.01),2)
    

    The sum does not affects the operation, but solves the ambiguity.

    Best regards.

    Thread Starter Toto146

    (@toto146)

    Hi @codepeople,

    that was the trick!!!

    Thanks!

    Best regards
    Thorsten

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Wrong RoundUp->RoundDown’ is closed to new replies.