I'm replying to a bunch of people at once here...

Firstly, jmcnamara, I'm not sure exactly how that works, but it looks really neat. OOC, what does the ~~%_ do?

Just a general comment: My goal was to get something that approximates the truth, rather than represents it exactly. I would prefer 0.039 to be given as 1/25, rather than 974/24975, because I'm looking for "how many hands (roughly) out of 25 or less am I going to get what I'm looking for".

My code currently gives it as 1/23, which isn't very good at all, though! :)

I'm booted into Windows (and the downvotes flow in...) right now, so I'll tweak my code in a little bit, but I think that by narrowing the tolerance, I'd get a little closer to 1/25.

I like Roger's error/tolerance checking. It's much more elegant than what I've got. The reduction sub is pretty awesome too. I remember thinking about doing that, but I cheated by starting with the lowest denominators and numerators, and brute-forcing it, instead. That sub would be great to post to snippets though. :)

ysth, that's a sweet, sweet code. :)


In reply to Re: Percentages to Fractions by David Caughell
in thread Percentages to Fractions by David Caughell

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.