Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Decimals to Fractions
Message
From
01/07/1999 15:00:39
 
 
To
01/07/1999 14:54:53
Kenneth Downs
Secure Data Software, Inc.
New York, United States
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00236602
Message ID:
00236636
Views:
10
Thanks, this just may work for what I'm doing.



>This is a more general solution that will work for .25 (unity numerator) and .625 (non-unity numerator).
>
>Add the fraction to itself repeatedly until it no longer has a decimal portion. If you keep adding .625 to itself you eventually get 5 after adding 8 times (remember to include the first .625 as one of the adds!).
>
>Of course, with true irrationals this will put the computer in an infinite loop, so I guess you have discovered the first advantage of limited numeric precision <s>.
>
>>What about .625. This is really 5/8, but the 1/.625 = 1.60. I can't find a way around this one. Any ideas?
>>
>>Thanks
>>
>>>Brian,
>>>
>>>Off the top of my head, I'd say 1 / .25 = 4, which is your denominator. Divide 1 by your decimal and you get the denominator x in the expression 1/x.
>>>
>>>For 2.25 (and other mixed numbers), use this approach:
>>>1. Divide 1 by the decimal portion to get your denominator
>>>2. multiply the denominator by the integer portion, add 1, that's your numerator.
>>>
>>>>Has anyone ever seen a routine that will take a decimal number, and output a string that is formatted as a fraction. For instance, send in .25, and it will return "1/4". Any help would be great.
>>>>
>>>>Thanks
Brian McCord
President
Sagacity Systems
Previous
Reply
Map
View

Click here to load this message in the networking platform