This should keep your 4 decimal places
'**********
A VAR BYTE ' 0 to 59 (10 for your example)
B VAR WORD '1000 to 9999 (4715 for your example) must be 4 digits
X VAR BYTE
DIGIT VAR BYTE[4]
FOR X = 0 TO 3
DIGIT[X] = B DIG X
NEXT X
FOR X = 3 TO 0 STEP -1
A = A * 10 + DIGIT[X]
DIGIT[X]= 0
Here:
IF A >= 60 THEN
A = A – 60
DIGIT[X] = DIGIT[X] + 1
GOTO Here
ENDIF
NEXT X
B = DIGIT[3]*1000+Digit[2]*100+Digit[1]*10+Digit[0] ' always 4 digits
IF A > 29 THEN B = B + 1
'**********
Try
10.4715
A=10, B = 4715
B = 1745
(Answer = .1745)
Try
1.1
A = 1
B = 1000
B = 183
(Answer = .0183)
Try
59.9999
A=59
B=9999
B=10000
(Answer =1.0000)
Untested but works on paper. If you are not always dividing by 60 then change to variable and calculate (A / denominator) first in a similar manner. If your values are going to change a lot then work in binary or hex with a fixed point math approach (google "fixed point math division" for lots of algorithms).
Good Luck,
Paul Borgmeier
Salt Lake City, Utah
USA
Bookmarks