in reply to Want to Truncate A Number... NOT round it

TMTOWTDI:

my $n=34.57889; $n=~/(-?\d+\.\d{3})/; print "$n - $1\n";

Update: Added -? to the regex to handle negative numbers (thanks halley)

CountZero

"If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law

Replies are listed 'Best First'.
Re: Re: Want to Truncate A Number... NOT round it
by halley (Prior) on Feb 11, 2004 at 21:15 UTC
    Breaks on negative numbers.

    --
    [ e d @ h a l l e y . c c ]