bilbozilla has asked for the wisdom of the Perl Monks concerning the following question:

I need some help with this one. I have the data and I want it formatted to carry the number out to 2 decimal places. Here is the code:
my ( $wantedx, $wantedy ) = ( $wanted =~ /($decimal).*?($decimal)/ );
Could you please assist me on this one?

Replies are listed 'Best First'.
Re: formatting numerical output
by data64 (Chaplain) on Apr 12, 2003 at 02:30 UTC
Re: formatting numerical output
by blokhead (Monsignor) on Apr 12, 2003 at 00:13 UTC
    my $blah = sprintf("%.2f", 3.1415926535); print "$blah\n"; __END__ prints 3.14

    Keep in mind this doesn't round, only truncates decimals. If you want the result in two different variables (for the stuff before and after the decimal), split on /\./

    blokhead

Re: formatting numerical output
by The Mad Hatter (Priest) on Apr 12, 2003 at 00:18 UTC
    Check out Rounding. Search is your friend; please use it next time.