<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">use strict;

# Beautify a number.  Turn 3576281 into $3.6M, 143,999 into $144K,
#  and 1153 into $1,153.  Might want to think of generalizing it for
#  multi-currencies at some point.
# Doesn't deal with negative numbers.
#
sub beautify
{
    my $in = shift;
    my ($l, $d);

    if    ($in &gt;= 1000000000) { $l = 'B'; $d = 100000000.0;  }
    elsif ($in &gt;= 1000000)    { $l = 'M'; $d = 100000.0; }
    elsif ($in &gt;= 1000)       { $l = 'K'; $d = 100.0; }

    else { return "\$" . &amp;commify(sprintf('%0.2f', $in)); }

    $in = (int(($in / $d) + 0.5)) / 10.0;
    return sprintf "\$%.1f$l", $in;
}

# stolen from perlfaq5.  The author (not me) is a show-off
#
sub commify
{
    local $_  = shift;
    1 while s/^([-+]?\d+)(\d{3})/$1,$2/;
    return $_;
}

1;
</pre></body></html>