Re: Making a decimal to fraction converter



Firstly, you can present the results from the three text boxes as a string:
text1.text & " " & text2.text & "/" & Text3.text

Secondly, any repeating decimal can be represented as the correct fraction using code, but you haven't indicated what your problem with this procedure is.

How is the user indicating that the decimal number is repeating indefinately, or is the problem that you can't detect when it's a repeating decimal? This could probably be solved with a regular expression.

Or is the problem that you don't know how to reduce a regular repeating number to a fraction? This is relatively easy, once you know the characteristics. For instance, if its a simple set of repeating digits, just use:

(Repeats is the number of digits that are repeated, textbox1 has the number to convert)

s = Split(TextBox1.Text, ".")
s(0) = s(0) & s(1).Substring(0, repeats)

numerator = Val(s(0) & "." & s(1))

power = 10 ^ repeats

numerator = numerator - value

denominator = power - 1

then simplify if possible. If it's some unique digitis followed by a repeating portion you need to allow for that in the adjustment of the value, and then adjust the numerator and denominator by powers of 10 until you have eliminated the fractional part of the numerator.

"Kasha" <RomulanPrince@xxxxxxxxxxxx> wrote in message news:8350ED0C-6972-42CB-81BE-38C9509B1A6F@xxxxxxxxxxxxxxxx
The goal of the program is to convert decimals to fractions with only the input of a decimal number, and thus far, I've only been able to simplify nonrepeating decimal numbers. If I were to have the user specify the finest graduation, I'd need a drastically different code, and I'd be going beyond the goal of the program =\

Is my goal hopeless without specifying the finest graduation then?

-Jason
"Tom Dacon" <tdacon@xxxxxxxxxxxxxxxx> wrote in message news:ui4sIPNIJHA.3824@xxxxxxxxxxxxxxxxxxxxxxx
Jason, if you can have your users specify the finest graduation to output (say, 64ths, 8ths, quarters, etc.), or if you assume a certain finest graduation, you can convert a repeating fraction and then round to the finest graduation that the number converts to, and then reduce it if possible.

So for instance, your 1/3 is 0.33333... If your finest graduation is 128ths, multiply the 0.33333... by 128, getting 42.66666... and round to 43, giving youi 43 / 128ths.

Similarly, 1/9 is 0.11111... For 128ths, multiply 0.11111... by 128, getting 14.22222... Round to 14/128ths and reduce to 7/64ths.


Tom Dacon
Dacon Software Consulting

"Jason" <RomulanPrince@xxxxxxxxxxxx> wrote in message news:204A45ED-4C6D-43E6-AD43-BBCCA0F71073@xxxxxxxxxxxxxxxx
I'm making a program that will convert decimal inputs (in this case, in inches) and output a fractional answer. At the moment, I'm only able to output the fractional answer in three parts: A whole number text box, a numerator text box, and a denominator text box. I realize that this is probably the closest I'll get to having fractions displayed in VB, so that's no big deal. I'm able to simplify most numbers with some code I've written, but I'm unable to simplify anything that repeats infinitely (i.e.. 1/3). Is there any way to be able to simplify this?

I can give you the code I've already written if that would help.

Thanks!




.



Relevant Pages

  • Re: Making a decimal to fraction converter
    ... The common standard for indicating a repeating decimal is a trailing period. ... I can't see how you could do it without somehow specify the acceptable ... Is my goal hopeless without specifying the finest graduation then? ... you can convert a repeating fraction and then round to the ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Making a decimal to fraction converter
    ... This is the full text of a program that converts a decimal number to a fraction, and handles repeating decimals correctly, including the case where there is a portion of the fractional part that is non-recurring. ... Dim value As Double, numer As Double, denom As Double ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Making a decimal to fraction converter
    ... fraction, and handles repeating decimals correctly, including the case where there is a portion of the fractional part that is non-recurring. ... Note that the repeating test is not foolproof - for instance it will detect the repeating part of 1.25252 as 52, which might not be what was intended. ... This also means it will NOT work properly with decimal numbers created from a fraction, because the computer will usually round the last digit. ... Dim value As Double, numer As Double, denom As Double ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Fraction to decimal
    ... to output the decimal representation of the fraction as a list in a particular form. ... The first member of the list is the whole number of the decimal representation. ... matlab separate the period of the number from the decimals that come before it. ... of the number and intend to try to pick out the repeating decimal from there. ...
    (comp.soft-sys.matlab)
  • Re: Fractions for .999... (aka 1)
    ... Dr. Math explains that for any repeating decimal, ... What fraction corresponds to ... In that case, I wondered, if 1 is a rational number, and 1 equals ...
    (sci.math)

Loading