>>>>CLEAR >>>> >>>>?GetCommonFract_2(1) >>>>?GetCommonFract_2(0) >>>>?GetCommonFract_2(13/32) >>>>?GetCommonFract_2(0.25) >>>>?GetCommonFract_2(9/16) >>>>?GetCommonFract_2(31/16) >>>>?GetCommonFract_2(-15.125) >>>> >>>>FUNCTION GetCommonFract_2 >>>> LPARAMETERS; >>>> tnNumber >>>> >>>> LOCAL; >>>> lnWhole,; >>>> lnFrac,; >>>> lnNominator >>>> >>>> llSign = SIGN(tnNumber)=-1 >>>> tnNumber = ABS(tnNumber) >>>> lnWhole = INT(tnNumber) >>>> lnFrac = tnNumber-lnWhole >>>> lnNominator = 2^(LEN(RTRIM(STR(lnFrac,15,15),"0"))-1) >>>> >>>> RETURN IIF(llSign,'-','')+; >>>> IIF(EMPTY(lnWhole),IIF(EMPTY(lnFrac),'0',''),LTRIM(STR(lnWhole,15))+' ')+; >>>> IIF(EMPTY(lnFrac),'',LTRIM(STR(lnFrac*lnNominator,15))+'/'+LTRIM(STR(lnNominator,15))) >>>>ENDFUNC &&GetCommonFract_2 >>>>>>>>
lnNominator = 2^(int(LEN(RTRIM(STR(lnFrac,15,15),"0")*log(10)/log(2)))+1)>>>be more correct? Because for three decimal digits you need two to the power of ten to have your error below 0.001... and 3*log(10)/log(2) is 9.9658, and the +1 there gives you 10.