adccommunitymod (AutomationDirect) asked a question.

Do-More Rounding of Real Numbers

Created Date: July 20,2015

Created By: Dean

**** This post has been imported from our legacy forum. Information in this post may be outdated and links contained in the post may no longer work.****

Is there a better way to do this?


  • adccommunitymod (AutomationDirect)

    Created Date: July 20,2015

    Created by: bcarlton

    It seems easier to multiply by 10, truncate, then divide by 10.

  • adccommunitymod (AutomationDirect)

    Created Date: July 20,2015

    Created by: Dean

    Do you mean truncate instead of round for result R4? This wouldn't properly handle fractions 0.500 or greater. Or am I misunderstanding you?

  • adccommunitymod (AutomationDirect)

    Created Date: July 20,2015

    Created by: bcarlton

    Ok how about

    It seems easier to multiply by 10, round, (truncate - I guess not needed), then divide by 10.

  • adccommunitymod (AutomationDirect)

    Created Date: July 20,2015

    Created by: Do-more PE

    Like Bernie said, it can all go in one expression. R2 = ROUND(R1 * 10) / 10

  • adccommunitymod (AutomationDirect)

    Created Date: July 20,2015

    Created by: Dean

    Okay I get it now. Thanks to both of you.

  • adccommunitymod (AutomationDirect)

    Created Date: July 20,2015

    Created by: bcarlton

    Do-More 1.41 using the Simulator

    When I place

    ROUND(R1 * 10) / 10

    In a MATH instruction I get an answer for the equivalent of

    ROUND((R1 * 10) / 10 ) (In other words - ROUND(R1) )

    If I try to place parentheses like this to force 'multiply ' - 'ROUND ' - 'divide '

    (ROUND(R1 * 10)) / 10

    it deletes them and goes back to

    ROUND(R1 * 10) / 10

    I ended up having to break it into separate MATH blocks to get it right.

    Expand Post
  • adccommunitymod (AutomationDirect)

    Created Date: July 20,2015

    Created by: Do-more PE

    Interesting. I'll pass that along to HOST to see what they have to say about it.

  • adccommunitymod (AutomationDirect)

    Created Date: July 20,2015

    Created by: bcarlton

    Yup - that does seem to do it. It's strange though, the 'R ' should have clued in the compiler that 'Real ' math was involved.

  • adccommunitymod (AutomationDirect)

    Created Date: July 20,2015

    Created by: BobO

    Please tell me what you are getting that is inconsistent with what you expect.

    Edit: ROUND returns an integer...

  • adccommunitymod (AutomationDirect)

    Created Date: July 20,2015

    Created by: bcarlton

    The original poster wanted to round a Real to the first decimal position.

    I suggested a 'times ten ' - 'ROUND ' - 'divide by ten ' sequence. I did it up in Do-more 1.41 with the simulator using 3 MATH instructions to verify.

    Do-more PE suggested 1 MATH instruction using ROUND(R1 * 10) / 10 as the expression.

    I tried that but only got a rounding to the lowest integer position.

    Mike Nash suggested replacing 10 with 10.0 in the expression in the single MATH instruction.

    I tried that and it worked.

    Expand Post
10 of 22