Results 1 to 4 of 4

Thread: Is there a formula or algorithm...

  1. #1

    Thread Starter
    Fanatic Member Nove's Avatar
    Join Date
    Jul 2004
    Posts
    736

    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.

  2. #2
    pathfinder NotLKH's Avatar
    Join Date
    Apr 2001
    Posts
    2,397

    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.

  3. #3

    Thread Starter
    Fanatic Member Nove's Avatar
    Join Date
    Jul 2004
    Posts
    736

    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.

  4. #4
    pathfinder NotLKH's Avatar
    Join Date
    Apr 2001
    Posts
    2,397

    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
  •  



Click Here to Expand Forum to Full Width