in reply to Arithmetic with fractions

There's a module (I never used) called Math::Fraction which seems to do the trick. It even handles mixed fractions:

use Math::Fraction; $a = frac("10 3/4"); $b = frac("1/2"); $c = frac("2/5"); $d = $a * $b + $c; print("$d\n");

It supports:

+ - / * + += -= *= /= ++ -- abs <=> == != < <= > >= ** sqrt

and has some useful conversion methods.

Replies are listed 'Best First'.
Re^2: Arithmetic with fractions
by initself (Monk) on Feb 07, 2008 at 19:42 UTC
    I fed Math::Fractions a decimal value of 23.7800 which it interpreted as 214/9 which in decimal value is 23.777777777777777777777777777778. I couldn't figure out if I should *not* be using the frac() method on a decimal value or whether or not the module is buggy. Can you?