| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
||||
|
Quote:
hmm, watch the process, this may help: Code:
.75->A .75*100->A gcd(A,100)->B A/B->C 100/B->D Output(1,1,C) Output(1,3,"/") Output(1,5,D) i left space so that it displays "3 / 4" instead of "3/4"...so that double digits are allowed. if you think you need triple digist you can give more space. if you want it to float, then you need more code. but do you understand the math of finding the numerator and denominator? |
|
||||
|
fixed it up a bit and made it fancy...now it floats
Code:
Prompt A //decimal to convert to fraction A*10000->A gcd(A,10000)->B A/B->C 10000/B->D If C/10<1 Then 1->Z Goto 99 Else If C/100<1 Then 2->Z Goto 99 Else If C/1000<1 Then 3->Z Goto 99 Else 4->Z //Should be enough space End Lbl 99 ClrHome Output(1,1,C) Output(1,1+Z,"/") Output(1,2+Z,D) and that will handle a 4 digit numerator with any size denominator. enjoy! ![]() Last edited by MrLarkins : April 14th, 2008 at 01:39 PM. |
|
|||
|
Improvement
I like that solution, but it would be easier to do "int(log(x))+1" instead of checking to find the number of digits.
|
|
||||
|
Quote:
very nice digit finder...eloquent, i've never seen that before. but i incorporated it into the program Code:
Prompt A //decimal to convert to fraction A*10000000->A gcd(A,10000000)->B A/B->C 10000000/B->D int(log(C))+1->Z Lbl 99 ClrHome Output(1,1,C) Output(1,1+Z,"/") Output(1,2+Z,D) that cut the code quite a bit. thanks. |
|
||||
|
how likely is that, i mean get serious...even the most sophisticated calculators have a digit limit of 8 or 9
even the TI84's built in >FRAC feature won't convert YOUR decimal to a fraction. be helpful instead of a nuisance Last edited by MrLarkins : April 15th, 2008 at 07:56 AM. |
|
|||
|
More of a solution
My friend actually made a program like this. I helped him... what we did was multiply the number by 10, in a loop, then we checked if the fractional part cancelled out, like this:
.010101->N N->T for(A,1,10) 10T->T if fPart(T-N)<(10^-A) Then A->R:10->A End End Basically, you can take R (the number of repeated digits) and do something with that to format the fraction. Jaggraffamel should know more about that... I'm not sure if that's the actual code (or if it works as is) but that's the general idea... hope it's useful. |
|
||||
|
Quote:
that's very nice, i'd would have never thought of that....but you got a parathesis in the wrong spot. Code:
Prompt->N N->T for(A,1,10) 10T->T if fPart(T)-N<(10^-A) Then A->R:10->A End End but how to integrate that into a program that does both terminating and repeating decimels...and then also decimals that have a non-repeating part before the repeating part, like .00102010201020102... hmmm, more thinking. Last edited by MrLarkins : April 16th, 2008 at 11:56 AM. |
|
|||
|
...
Quote:
Well, theoretically, it would. You see, the only decimals that repeat have denominators that end in 1, 3, 7, and 9. Google 'Vedic Mathematics' and look for "by one more than the one before" to see what I mean. You could probably reverse the division alg (from Vedic Math) to come out with a workable fraction (with a denominator that ends in 9), which could then be reduced through factoring. All the other denominators don't repeat, however, so there is no problem, see? If you don't quite understand, just say so. I'll try to show the act |