PDA

Click to See Complete Forum and Search --> : how do you put a never ending decimal into a fraction?



audioaxes
08-12-2002, 07:51 AM
express as a fraction in lowest terms: .313131313131.....

ericlin
08-12-2002, 12:14 PM
0.313131313131.....
The repeated part is 31, so this is 31/99;

For 2/7=0.285714285714286;
The repeated part is 285714; so this is 285714/999999;

However, to get the "lowest" part, we need to divide them by "common factorial"; That seems difficult and complex;

My brutal way is test integer from 1 to 10000000; to find out any integer fraction that fits for this number;

The loop below, will find 2/7 at the second loops. If we are going to find 999998/999999, it will goes 999998 loops before it got the answer;



a = 2/7;
trace(a);
for (var k = 1; k<100000; k++) {
//equation k/m=a; m should be integer;
m = k/a;
if (Math.abs(int(m)-m)<0.000000000001) {
//this means integer;
trace(k+"/"+m+"="+k/m);
break;
}
}

audioaxes
08-12-2002, 10:45 PM
thanks -i was never taught some stuff that im expected to know for summer HW

muckyMuckMan
08-16-2002, 06:01 PM
If you want to find a fraction to practically any decimal number using Flash, I have written a decimal to fraction (mixed fractions too) convertion prototype. You can get it here: http://home.earthlink.net/~funbox/math/decimalToFraction.txt