|
-
Feb 14th, 2005, 05:19 PM
#1
Thread Starter
Fanatic Member
Is there a formula or algorithm...
for converting decimals to fractions? For instance, some way in VB6 I could convert something like .678584 to the most simplified fraction? If there is, how many places past the decimal point is this reliable? Thanks.
-
Feb 14th, 2005, 08:52 PM
#2
Re: Is there a formula or algorithm...
Will you need a method for repeating decimals, ie .765765765765...?
If Not, if they always terminate, then multiply it by (10^n) to get a whole integral value.
Then find the GCD between it and 10^n. Divide both by this GCD.
You'll end up with a usable set of (numerator, denominator) for your fraction.
-
Feb 14th, 2005, 09:23 PM
#3
Thread Starter
Fanatic Member
Re: Is there a formula or algorithm...
sounds good, i'll try to work it out in code and come back if I have any problem. Thanks.
-
Feb 15th, 2005, 07:21 AM
#4
Re: Is there a formula or algorithm...
If you do have a repeating decimal type, then, by example, this is how you'd deal with it:
Say you had .1234123412341234...
Thus:
X=.12341234...
10000X=1234.12341234...
10000X-X=1234.12341234... - .12341234....
9999X=1234
X=(1234/9999)
So, now just reduce the fraction .
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|