Ok, here's my rediculous approach that will give the exact answer... Thanks to tilly for the 'gcd' function, that was great! :-D

use strict; use warnings; while (<DATA>) { chomp; my $a = $_; $a =~ s/^\d?\.0*?//; # strip 0.0 part from 0.035 my $b = length($_) - 2; # how many zero's we need # assume in 0.0x form my $c = 10 ** $b; my $gcd = gcd($a, $c); $a /= $gcd; $c /= $gcd; print $_, "\t", "$a/$c", "\n"; } # ---- borrowed from tilly's code ---- sub gcd { my ($n, $m) = @_; while ($m) { my $k = $n % $m; ($n, $m) = ($m, $k); } return $n; } __DATA__ 0.035 0.037 0.039 0.041 0.043 0.046 0.048 0.058 0.068 0.078 0.35 0.37 0.39 0.41 0.43 0.46 0.48 0.58 0.68 0.78

And the output -
0.035 7/200 0.037 37/1000 0.039 39/1000 0.041 41/1000 0.043 43/1000 0.046 23/500 0.048 6/125 0.058 29/500 0.068 17/250 0.078 39/500 0.35 7/20 0.37 37/100 0.39 39/100 0.41 41/100 0.43 43/100 0.46 23/50 0.48 12/25 0.58 29/50 0.68 17/25 0.78 39/50


In reply to Re: Percentages to Fractions (The good, the bad and the **rediculous**) by Roger
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.