Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re^2: decimal to fraction

by huck (Vicar)
on Sep 12, 2017 at 13:07 UTC ( #1199198=note: print w/replies, xml ) Need Help??


in reply to Re: decimal to fraction
in thread decimal to fraction

Heh, While technically correct, IMHO this is kinda cheating

9: 49420098210293 / 100000000000000 = 0.49420098210293 (0)
and on the same scale amazingly useless result :-):

Replies are listed 'Best First'.
Re^3: decimal to fraction
by pryrt (Curate) on Sep 12, 2017 at 13:47 UTC

    The numerator and denominator are mutually prime (no common factors), and thus the fraction is fully reduced. How else would you represent it as a fraction?

    #!/usr/bin/env perl -l use warnings; use strict; ##### # [id://56906] for quick gcf sub gcf { my ($x, $y) = @_; ($x, $y) = ($y, $x % $y) while $y; return $x; } ###### print gcf(49420098210293,100000000000000); # prints 1 ##### use Math::Prime::Util qw/is_prime factor/; print is_prime(49420098210293); # not prime (I wasn't sure + when I started my answer) local $, = 'x'; print factor(49420098210293); # 113x4729x92481709 print factor(100000000000000); # 2x2x2x2x2x2x2x2x2x2x2x2x +2x2x5x5x5x5x5x5x5x5x5x5x5x5x5x5 # no common factors

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1199198]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (6)
As of 2017-10-18 06:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My fridge is mostly full of:

















    Results (242 votes). Check out past polls.

    Notices?