« lib/Perlmazing/Perlmazing/Precompile/remove_duplicates.pm
↑ Summary
blib/lib/Perlmazing/Perlmazing/rmdir.pm »
| 1 | use Perlmazing qw(is_number); | ||
| 2 | use CLDR::Number; | ||
| 3 | my $cldr = CLDR::Number->new(locale => 'en'); | ||
| 4 | my $decf = $cldr->decimal_formatter; | ||
| 5 | our @ISA = qw(Perlmazing::Listable); | ||
| 6 | |||
| 7 | sub main { | ||
| 8 | return unless $_[0]; | ||
| 9 | my $n = $_[0]; | ||
| 10 | my $point = $decf->{decimal_sign}; | ||
| 11 | my $comma = $decf->{group_sign}; | ||
| 12 | my $plus = $decf->{plus_sign}; | ||
| 13 | my $minus = $decf->{minus_sign}; | ||
| 14 | my $sign = substr($n, 0, 1); | ||
| 15 | my $decimals; | ||
| 16 | if ($sign =~ /^([$plus]|[$minus])/) { | ||
| 17 | $n = substr $n, 1; | ||
| 18 | } else { | ||
| 19 | undef $sign; | ||
| 20 | } | ||
| 21 | $n =~ s/[^\d$point$comma]+//g; | ||
| 22 | return unless $n; | ||
| 23 | if ($n =~ /[$point](\d+)$/) { | ||
| 24 | $decimals = $1; | ||
| 25 | $n =~ s/[$point]\d+$//; | ||
| 26 | return if $n =~ /[$point]/; | ||
| 27 | } | ||
| 28 | $n = 0 unless $n; | ||
| 29 | $n = "$sign$n" if $sign; | ||
| 30 | $n =~ s/$comma//g; | ||
| 31 | return unless $n; | ||
| 32 | $n = $decf->format($n); | ||
| 33 | $n .= "${point}${decimals}" if $decimals; | ||
| 34 | $_[0] = $n; | ||
| 35 | } | ||
| 36 | |||
| 37 | 1; |