This is a bit over-generalized, but allows for easy extension.

>perl -wMstrict -le "use Regexp::Common qw(number); ;; my %conversion = ( K => 1_000, M => 1_000_000, B => 1_000_000_000, L => 100_000, LAKH => 100_000, ); my $suffix = qr{ (?i) @{[ join q{|}, reverse sort keys %conversion ]} }xms; ;; for my $n (qw(28.04B 376.92M 12.3K 98.76Lakh 7l 23.45k), @ARGV) { my ($base, $mult) = $n =~ m{ \A ($RE{num}{real}) ($suffix) \z }xmsg; print qq{'$n' => }, $base * $conversion{uc $mult}; } ;; my $s = 'w 28.04b x 376.92M y 98.76L z'; $s =~ s{ ($RE{num}{real}) ($suffix) } { $1 * $conversion{uc $2} }xmsge; print qq{'$s'}; " '28.04B' => 28040000000 '376.92M' => 376920000 '12.3K' => 12300 '98.76Lakh' => 9876000 '7l' => 700000 '23.45k' => 23450 'w 28040000000 x 376920000 y 9876000 z'

Update: Added multiple conversions in a string to example.


In reply to Re: convert last digit in decimal by AnomalousMonk
in thread convert last digit in decimal by baperl

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.