How to round number using integer only


Closed Thread
Results 1 to 3 of 3
  1. #1
    Join Date
    Jan 2011
    Location
    Harare
    Posts
    5

    Default How to round number using integer only

    Hello all,
    I'm stuck on that one. How do you round a number using integer only? for example if I have a variable like 4557 I would like the results to become 4560 because the last digit is higher than 5 on the other end if I have a variable like 4554 the last digit is less than 5 so the variable remains 4554.
    The trick is how to isolate the last digit to make the comparison? Any idea?
    Regards,
    Yves

  2. #2
    Join Date
    May 2008
    Location
    Italy
    Posts
    825


    Did you find this post helpful? Yes | No

    Default Re: How to round number using integer only

    You can use the DIG comand!

    Let assume your word variable that contains 4557 is named R_Value, then:

    AA0 VAR BYTE

    AA0 = R_Value DIG 0
    If AA0 > 5 then
    R_Value = R_Value + (10 - AA0)
    ENDIF

    .... and you will round as requested.

    Cheers


    Al.
    Last edited by aratti; - 6th March 2011 at 13:20.
    All progress began with an idea

  3. #3
    Join Date
    Oct 2004
    Posts
    440


    Did you find this post helpful? Yes | No

    Default Re: How to round number using integer only

    Quote Originally Posted by Yvesmazzon View Post
    Hello all,
    if I have a variable like 4557 I would like the results to become 4560 because the last digit is higher than 5 on the other end if I have a variable like 4554 the last digit is less than 5 so the variable remains 4554.
    Regards,
    Yves
    var = var * 10
    say calculation arrives at 45576
    var = var +5
    var = var / 10
    answer 4558

    Norm

Members who have read this thread : 2

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts