May 1, 201411 yr Hello, I was trying to solve my problem using this thread: http://fmforums.com/forum/topic/32190-formatting-decimal-numbers-to-fractions/ But I can't for the life of me figure out how to modify this calculation without the constraints specified in this thread. I just want my decimal to display as a fraction...no constraints. Is this possible?
May 1, 201411 yr Author Nevermind! I found a calculation that seems to be working so far: Let ( [precision=10000; p0=Abs(number);n0=Mod(p0;1); p1=1/Case(n0 ;n0;1);n1=Mod(p1;1); p2=1/Case(n1 and (p1/n1<precision);n1;1);n2=Mod(p2;1); p3=1/Case(n2 and (p1*p2/n2<precision);n2;1);n3=Mod(p3;1); p4=1/Case(n3 and (p1*p2*p3/n3<precision);n3;1);n4=Mod(p4;1); p5=1/Case(n4 and (p1*p2*p3*p4/n4<precision);n4;1);n5=Mod(p5;1); p6=1/Case(n5 and (p1*p2*p3*p4*p5/n5<precision);n5;1);n6=Mod(p6;1); p7=1/Case(n6 and (p1*p2*p3*p4*p5*p6/n6<precision);n6;1); d=Round(p1*p2*p3*p4*p5*p6*P7;0); n=Round(p0*d;0);nf=Round(n0*d;0); sgn=Choose(Sign(number)+1;"-";"";""); whole=Div(n;d); fraction=Case(d=1;"";nf;nf&"/"&d;"")]; Trim(sgn&Case(not p0;0;whole;whole&" ";"")&fraction))
May 1, 201411 yr I found a calculation that seems to be working so far: Please give the author proper credit by including a link to the original post. I believe this one is by Bob Weaver? I just want my decimal to display as a fraction...no constraints. Is this possible? No constraints whatsoever? Yes, it is possible: just convert the decimal to a fraction using a denominator that is a power of 10, so that: 0.5 --> 5/10 0.75 --> 75/100 0.125 --> 125/1000 3.1428571428571429 --> 3 1428571428571429/10000000000000000 etc. Whether this is useful for anything is another question. Typically one would try to reduce the fraction to the smallest integers possible, i.e.: 0.5 --> 5/10 --> 1/2 0.75 --> 75/100 --> 3/4 0.125 --> 125/1000 --> 1/8 The question then becomes what do you do with a decimal such as 0.33 - do you leave it as 33/100, or do you regard it "close enough" to be represented as 1/3? Because that's what the calculation above does: if your precision parameter is 100 or lower, 0.33 will become 1/3; set it higher and it will be left as 33/100. And that's definitely a constraint.
May 1, 201411 yr Author Thanks Comment for your help as always. I would love to give the author credit (and would have) but alas, I copied the calculation from a woman who posted on another forum who got it from some place else and she didn't reveal where she got it from. I didn't see the point in posting the link to the other forum for that reason but if you feel otherwise let me know and I'll go back and try to find it again.
May 1, 201411 yr Well, let's see: [searching...] Ah, there it is: http://fmforums.com/forum/topic/34052-calc-to-reduce-fractions/ I copied the calculation from a woman who posted on another forum who got it from some place else and she didn't reveal where she got it from. Perhaps you should reprimand her as I did you ...
May 1, 201411 yr Author http://www.filemakertoday.com/com/showthread.php/10520-Decimals-to-Fractions-Newbie Here is where I got it from, at the very bottom. It didn't even occur to me it could have come from here because my search on this forum never turned up the string you found. I see now that someone had posted the link for her that I had somehow completely overlooked. Her comment led me to believe she found it somewhere else on her own. It was not my intention to not give credit where it was due. On another note, would you kindly be able to lead me to a thread that discusses the ability to do it the other way around, i.e. display a fraction entered into a field as a decimal? Once again my searches are turning up nothing but dead ends.
May 1, 201411 yr do it the other way around, i.e. display a fraction entered into a field as a decimal? This is not a matter of displaying - you just need to calculate the decimal value of the fraction by dividing the numerator by the denominator and (if you have it) adding the integer part. The real question here is how will you enter the fractions into a (text) field. Ideally, you would use three different number fields for this purpose. Otherwise you need to set up some rules and enforce them. For example, if there always will be a space between the integer and the numerator (but not anywhere else) you could do = Evaluate ( Substitute ( Fraction ; " " ; "+" ) ) This will convert "5/8" to .625, "1 1/4" to 1.25 and "28" to 28 - but it will error at "1 / 2".
Create an account or sign in to comment