in reply to Where's that function

Fore!

my $x=12.3456789; my ($a,$b)=split (/\./,$x); $b=substr $b,0,2; $x=$a.'.'.$b;

____________________
Jeremy
I didn't believe in evil until I dated it.

Replies are listed 'Best First'.
Re: Re: Where's that function
by dkubb (Deacon) on Feb 05, 2001 at 09:45 UTC
    Here we go jepri, I love golf =).. fore!
    my $num = 12.3456789; $num = substr($num, 0, index($num, '.') + 3); print $num; #prints 12.34

    Also, here's another that is probably overkill:

    use Math::Currency; my $num = 12.3456789; $num = Math::Currency->new($num);

    This handles the rounding up/down of the number, where the preceding golf attempt does not. The original post did not ask for rounding, though.

Re: Re: Where's that function
by MrNobo1024 (Hermit) on Feb 05, 2001 at 21:20 UTC
    this method is a little faster and shorter, but it dosen't work right when $x is negative:
    my $x = 12.3456789; $x = int($x*100)/100;