There, it now works with negatives. My bad on the earlier version :)$fraction = '-32 2/5'; &fconv(\$fraction); sub fconv { my $f = shift; if ($$f =~ /(-?) ?((\d+) )?(\d+) ?\/ ?(\d+)/) { $$f = ($1 eq '-' ? -1 : 1) * ($3 + $4/$5); } }
As for Perl's problems with number management, that can't really be helped. You can always use the fractions class mentioned above, or round your results to the nearest thousandth, which should produce the same results.
In reply to Re^3: Arithmetic with fractions
by TedPride
in thread Arithmetic with fractions
by algonquin
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |