rounding numbers

klaasje

Member
Hello all

I have a question.

If i have a reading in b2 from 88 and i want the same in b3 divided by 10 then i get 8 instead of 9 (more then 85 should be 9)

How can i change that?


Thanks in advance
 

oracacle

Senior Member
you will need to check the remainder amount

Code:
let b4 = b2 // 10
if b4 => 5 then
   let b3 = b2 / 10 + 1
else
   let b3 = b2 / 10
end if
 

AllyCat

Senior Member
Hi,

To round to the nearest integer, you can add half the divisor before the division, i.e. 5 for your example.

Thus; b3 = b2 + 5 / 10, (or b3 = 5 + b2 / 10 is less likely to be misunderstood).

For a more general version, you can write:

Code:
b2 = 88
symbol divisor = 10
b3 = divisor / 2 + b2 / divisor      ; round (up) to the nearest integer
sertxd(#b2," / ",#divisor," = ",#b3)
Note that will round 85 / 10 up to 9, which you might not expect, but is arguably correct. ;)

Cheers, Alan.
 
Last edited:
Top