Thread: Program to convert from decimal to fraction

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Ticked and off
    Join Date
    Oct 2011
    Location
    La-la land
    Posts
    1,728
    Quote Originally Posted by iMalc View Post
    It needs no special case code for mixed-numbers, a.k.a improper fractions
    Does it yield a good approximation for those, or does it just punt? What does it yield for example for 0.9999127?

    Quote Originally Posted by iMalc View Post
    So, um yes I know the ideal algorithm. If you search the next hard enough you'll find it.
    Bold claim. Care to link to the basis (articles, references?) of that claim?

  2. #2
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    Quote Originally Posted by Nominal Animal View Post
    Does it yield a good approximation for those, or does it just punt? What does it yield for example for 0.9999127?


    Bold claim. Care to link to the basis (articles, references?) of that claim?
    Just tested that and it gives 9999127 / 10000000.

    Unfortunately I never recorded where I got the algorithm from, so I'm having a hard trouble finding it. I guess I'll have to say that I mean ideal for him, until I can substantiate any further claim.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  3. #3
    Ticked and off
    Join Date
    Oct 2011
    Location
    La-la land
    Posts
    1,728
    Quote Originally Posted by iMalc View Post
    I guess I'll have to say that I mean ideal for him
    Yes, I think I can agree to that.

    Your implementation is C++, but rewriting it to C should be easy for the OP.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Question regarding extraction of value from a decimal fraction
    By abhishekcoder in forum C Programming
    Replies: 2
    Last Post: 04-08-2012, 12:57 PM
  2. Convert Decimal IP To Dotted Decimal Notation
    By MaSSaSLaYeR in forum C Programming
    Replies: 11
    Last Post: 11-16-2011, 06:18 PM
  3. Replies: 15
    Last Post: 10-06-2009, 11:20 PM
  4. how to convert decimal to hexa decimal in C/
    By kalamram in forum C Programming
    Replies: 4
    Last Post: 09-03-2007, 07:39 AM
  5. Fraction outputted as decimal
    By blindman858 in forum C++ Programming
    Replies: 3
    Last Post: 06-04-2005, 01:17 PM