>LPARAMETER lcString >LOCAL lnNum, lnDom, lnMax, lnDecimal, lnPower >lnMax = 64 >lnNum = 1 >lnDom = 2 >lnPower = 1 >lnDecimal = VAL(lcString) >* Decimal part only >DO WHILE lnDom <= lnMax > lnDom = 2^lnPower > lnNum = lnDecimal * lnDom > IF ROUND(lnNum,0) == lnNum > EXIT > ENDIF > lnPower = lnPower + 1 >ENDDO >RETURN ALLTRIM(STR(lnNum)) + "/" + ALLTRIM(STR(lnDom))+["] >>
FUNCTION Dec2Fraction LPARAMETER tnDec LOCAL lcresult, lnpt, lnnum, lcdec, lnexp,; lndenom, lcdenom lcresult = "" lcdec = TRANSFORM(tnDec) lnpt = AT(".", lcdec) IF lnpt > 0 lnexp = LEN(SUBSTR(lcdec, lnpt + 1)) lndenom = 2 ^ lnexp lnnum = 0 DO WHILE lnnum / lndenom # tnDec lnnum = lnnum + 1 ENDDO lcresult = TRANSFORM(lnnum) + "/" + TRANSFORM(lndenom) ENDIF RETURN lcresult ENDFUNCThis only works for fractions where the denominator is a power of 2.