I hate to say it as the regex way is kinda cool, but
$y = int($x * 100)/100;
is much faster, at least on my machine.
even
$x = sprintf("%.2f", int($y * 100)/100);
is marginally faster and pads the output to two decimal points..
John Moon wrote:
> One way to do it ...
>
> perl -e '$x=1234
On Tue, Jul 10, 2001 at 12:44:09PM -0700, Thomas Jakub wrote:
: okay... so how do I drop of all but two decimal
: points in perl?
Give sprintf() a try:
my $float = 4.3456;
[... some code ...]
$float = sprintf "%.2f", $float;
s?printf() will do it's best to round for you too, allthough th
At 04:11 PM 07/10/2001 -0400, Moon, John wrote:
>One way to do it ...
>
> perl -e '$x=1234.5678; ($y)=$x=~/(\d*\.{0,1}\d{0,2})/;print $y ."\n";'
heh...that was pretty close to perl bowling ;-)
Don't do wierd contrortions with regexps when theres a simple built-in
function to pull off the same r
One way to do it ...
perl -e '$x=1234.5678; ($y)=$x=~/(\d*\.{0,1}\d{0,2})/;print $y ."\n";'
-Original Message-
From: Thomas Jakub [mailto:[EMAIL PROTECTED]]
Sent: July 10, 2001 15:44
To: [EMAIL PROTECTED]
Subject: dropping off a few decimal points
okay... so how do I drop of all but