Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Convert decimal to fraction
Message
From
10/02/2003 18:14:25
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00751688
Message ID:
00751709
Views:
19
This message has been marked as a message which has helped to the initial question of the thread.
Here is some code. I didn't do any error checking.
lnfraction = .875

lcfraction = getfraction(lnfraction)

? lcfraction

return

procedure getfraction (tndec as number) as character

  lndenominator = 100000
  lnnumerator = tndec * lndenominator
  lnfactor = 1
  i = 2
  lnend = lndenominator/2
  do while i < lnend
    if lnnumerator % i = 0 and lndenominator % i = 0 && factor of both numerator and denominator
      lnfactor = lnfactor * i
      lnnumerator = lnnumerator/i
      lndenominator = lndenominator/i
      lnend = lndenominator/2
    else  && try next higher
      i = i + 1
    endif
  enddo

  return alltrim(str(lnnumerator))+"/"+alltrim(str(lndenominator))

endproc
Carole Shaw
Fred Hutchinson Cancer Research Center

Eagles may soar, but weasels don't get sucked into jet engines.
Previous
Reply
Map
View

Click here to load this message in the networking platform