Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

Re: Percentages to Fractions

by I0 (Priest)
on Feb 22, 2004 at 05:29 UTC ( #330889=note: print w/replies, xml ) Need Help??

in reply to Percentages to Fractions

use strict; use POSIX; sub cf{ my($v,$p) = @_; my $i=int $v; $v -= $i; if( fabs($v)>$p ){ my($a,$n,$d)=cf(1/$v,$p*(1+abs$i)); return $i,$d,$a*$d+$n }else{ return $i,0,1; } } while( <DATA> ){ chomp; my ($i,$n,$d) = cf($_,.001); $n+=$i*$d; print "$_:\t$n/$d\n"; } __DATA__ 0.035 0.037 0.039 0.041 0.043 0.046 0.048

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://330889]
[james28909]: it would be to much work just to get around renaming three subs lol
[james28909]: but you could put it all in one sub and return the same data type that was inputted. i could write a small example maybe
[Lady_Aleena]: Their uses are also vastly different.
[Lady_Aleena]: The first two make hashes and arrays from a file, the third returns data from a pre-existing hash.
[Lady_Aleena]: Well, HoH and AoH respectively.
[Lady_Aleena]: But if you want to play, play. I don't mind. 8)

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (3)
As of 2017-05-24 05:10 GMT
Find Nodes?
    Voting Booth?