Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Convert Fractions to Decimal
Message
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00476506
Message ID:
00476643
Views:
31
Well. It is not that easy to go from decimal to fraction. Because 1/2 = 0.5 = 2/4 = 4/8, etc. So if you have 0.5 how do you know which fraction is the correct one?

But what you could do is:
lnCnt = 0
lnDec = 0.6
do while .T.
  lnCnt = lnCnt + 1
  lnResult = lnCnt * lnDec
  if lnResult == int(lnResult)
    exit
  endif
enddo

? "Fraction: " + allt(str(lnResult))+"/"+allt(str(lnCnt))
That should give you the first fraction met.

HTH,
- Erik Niese-Petersen

Crazy Dane in USA.
Previous
Reply
Map
View

Click here to load this message in the networking platform