>>>Is there a way to convert the string that has a slash to a numeric (without parsing the string)? For example, make "1/4" to .25, "1/2" to ".5" and so one?
>>>
>>>TIA
>>
>>depends on your definition of "parsing" ;-))
>>
>>luR = iif(vartype(m.lcS)=="C" and occurs("/",m.lcS), eval(m.lcS), m.lcS)
>
>How would you reverse that, Thomas?
>e.g. convert .25 to "1/4"
I did that once, but for inches only, and rounded it to eights. Something like
lparameter tnLen
lcInt=tran(int(tnLen), "999")
lnFrac=tnLen % 1
lnEights=round(lnFrac*8,0)
lcRet=ltrim(lcInt)+" "+tran(lnEights,"9")+"/8"
return lcRet
IIRC I also had some logic to see if lnEights was an even number, then it would be quarters, or if that was even, make it 1/2.
For the general case, I'd go for the divisors up to, say, 32, and then pick the one with the least rounding error.