Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Convert Fractions to Decimal
Message
 
To
16/02/2001 11:01:26
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00476506
Message ID:
00476658
Views:
23
Another part could be like this:

Procedure iDeci2Frac
LParameter pMixed
Local lcMixed, retval, lnWhole, lnNumer, lnDenumer

lcMixed=trans(pMixed)
lnWhole=val(left(lcMixed,at(".",lcMixed)-1))
lnNumer=val(substr(lcMixed,at(".",lcMixed)+1))
lnDenumer=val("1"+repl("0",len(substr(lcMixed,at(".",lcMixed)+1))))

do while lnNumer%2=0
lnNumer=lnNumer/2
lnDenumer=lnDenumer/2
enddo
do while lnNumer%5=0
lnNumer=lnNumer/5
lnDenumer=lnDenumer/5
enddo

retval=alltr(str(lnNumer))+"/"+alltr(str(lnDenumer))
do case
case lnWhole>0
retval=alltr(str(lnWhole))+" and "+retval
case lnWhole <0
retval="-("+alltr(str(-1*lnWhole))+" and "+retval+")"
endcase

Return retval
*----------
Best wishes



>>>>>>previous messages below

Hi George

Well that part was easy!

Thanks

>>Does anyone have code to convert a fraction to a decimal and from decimal to a fraction?
>>
>>
>>Thanks
>
>John,
>
>Assuming you mean a string
lnresult = EVALUATE(lcfraction)
Changing lnresult back to a string takes more work. Basically, it would be involve using lnresult as the numerator and 10, 100, or whatever as the denominator and finding the common factors.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform