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
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.
Re: How to round number using integer only
Quote:
Originally Posted by
Yvesmazzon
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