in reply to formatting numbers
sub number_format { my $num = shift; return $num unless $num; return undef unless $num =~ /^[0-9\.+-]+$/; $num =~ s/^([\+-])?//; my $sign = $1; $num =~ s/\.([0-9]+)$//; # must come before the call to abs(), be +cause here my $dec = $1; # a floating point value is still regard +ed as a string by perl, even if it's 0.00. $num = abs $num; $num = reverse $num; $num =~ s/(\d{3})/$1\,/g; $num =~ s/\.$//; $num = reverse $num; $num .= ".$dec" if $dec; $num = "$sign$num" if $sign; $num; }
|
|---|