Welcome to our new forum
All users of the legacy CODESYS Forums, please create a new account at account.codesys.com. But make sure to use the same E-Mail address as in the old Forum. Then your posts will be matched. Close

Re: Rounding Numbers

Niclas123
2013-10-03
2013-10-05
  • Niclas123 - 2013-10-03

    Try build a FB like this one, it should do the work.

    value := (input MOD 10);
    IF value <> 0 THEN
    Output := input + (10 - (input MOD 10));
    ELSE
    Output := input;
    END_IF
    

    /Niclas

     
  • Niclas123 - 2013-10-04

    NP, sure.

    value := (input MOD 10);
    IF value > 5 THEN
    Output := input + (10 - (input MOD 10));
    ELSE
    IF value = 5 THEN
    Output := input + (10 - (input MOD 10));
    ELSE
    IF value < 5Β  THEN
    Output := input - (input MOD 10);
    ELSE
    Output := input;
    END_IF
    END_IF
    END_IF
    

    /Niclas

     

Log in to post a comment.