in reply to convert last digit in decimal

my %mul = ( M => 1e6, B => 1e9, ); if ($num =~ s/([^0-9.]+)\z//) { my $suf = $1; die if !$mul{$suf}; $num *= $mul{$suf}; }

(Billion can also mean 1e12. Adjust if necessary.)

Replies are listed 'Best First'.
Re^2: convert last digit in decimal
by baperl (Sexton) on Aug 10, 2011 at 22:22 UTC
    thanks ikegami, this isn't working though.... here's what I have
    my $mult=chop($mcap); my $dec=$mcap-int($mcap); if ($mcap =~ s/([^0-9.]+)\z//) { my $suf=1; die if !$multiplier{$suf}; $mcap *= $multiplier{$suf}; } print "multiplier is $mult and decimal portion is $dec and mcap is $mc +ap\n";
    and this is the output
    multiplier is B and decimal portion is 0.200000000000003 and mcap is 1 +08.2
      Then I recommend you use the code I posted.