in reply to Arithmetic with fractions
This will convert a fraction or mixed number of any form to a decimal equivalent. The following are some possibilities:$fraction = '32 2/5'; &fconv(\$fraction); sub fconv { my $f = shift; if ($$f =~ /((\d+) )?(\d+) ?\/ ?(\d+)/) { $$f = $2 + $3/$4; } }
2/5
2 / 5
2 /5
32 2/5
32 2 / 5
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Arithmetic with fractions
by tachyon (Chancellor) on Sep 22, 2004 at 07:33 UTC | |
by TedPride (Priest) on Sep 22, 2004 at 08:07 UTC |