Hi,
PBP only deals with integer math, truncating (not rounding) anything to the right of any decimal point. In your case the largest number you're having in the calculation is 30/32 which will come back as 0 when executed because 30/32 = 0.9375, 0.9375*100 will be treated as 0*100.
To come around this you can multiply Dist by 100 before doing the division:
Dist = Dist * 100 'Will now be 100-3000
Percent = Dist / Maxval 'Will return 93, should be 93.75
To get even better results:
Dist = Dist * 1000 'Dist will now be 1000-30000
Percent = Dist / Maxval 'Will return 937 as a representation of 93.7
Then to display the value you can do:
HSEROUT ["Result: ", Percent / 10, ".", Percent // 10, "%"], 10, 13
Which should display 93.7
If Dist was, say 11 the "true" result is (11/32)*100 = 34.375% but you'll get
11000/32 = 343, displayed as 34.3
Is that good enough or do you need it to be rounded?
/Henrik.
Bookmarks