>>It would if you had
>>
>>#DEFINE true .T.
>>
>>>
>>>Absolute 1st class! Change true to .T. as Fox did not like this, but again: very good.
>>>Thanks for sharing with us.
>>>
>Sergey, of course, but that was not listed in the code.
>
> An other thing: I am less enthousiastic after some tests:
>
>
>0.33 results in 33/100
>0.333333333333333 results in 0/3
>0.3333333333333333 results in 1/3
>0.6666 results in 1/3
>
>I take it this has something to do with how VFP rounds
>
>Regards,
>
>Koen
local numerator, denominator
? Num2Fraction(-.3333333333333333, @m.numerator, @m.denominator)
FUNCTION Num2Fraction (x, numerator AS @, denominator AS @)
IF EMPTY(m.x)
STORE 0 TO numerator
STORE 1 TO denominator
RETURN '0'
ENDIF
STORE 10^MAX(LEN(RTRIM(CAST(m.x % 1 AS M),"0"))-2,0) TO denominator
PRIVATE n
STORE GCD(m.denominator, ROUND(m.x * m.denominator,0)) TO n
STORE m.denominator/m.n TO denominator
STORE ROUND(m.x * m.denominator,0) TO numerator
RETURN TRANSFORM(m.numerator) + '/' + transf(m.denominator)
ENDFUNC
FUNCTION GCD(i1,i2)
DO WHILE m.i2 # 0
STORE m.i1 % m.i2 TO i1
IF EMPTY(m.i1)
RETURN ABS(m.i2)
ENDIF
STORE m.i2%m.i1 TO i2
ENDDO
RETURN IIF(ISNULL(m.i2),DAY(NULL),ABS(m.i1))
ENDFUNC
FUNCTION LCM (i1,i2)
RETURN ABS( ROUND(m.i1 * m.i2,0) / EVL(GCD(m.i1, m.i2),NULL))
ENDFUNC