X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FNum2text.pm;h=2b2c51a8734c0114025daea573d515fd4b99c3fd;hb=37d14c11afd10049be58467770499b25268c1364;hp=895c4372663f175ba347e392333fefb0be5dccbc;hpb=4dbb09950c9f5596646537c12d991c99086fe7c1;p=kivitendo-erp.git diff --git a/SL/Num2text.pm b/SL/Num2text.pm index 895c43726..2b2c51a87 100644 --- a/SL/Num2text.pm +++ b/SL/Num2text.pm @@ -25,56 +25,55 @@ # GNU General Public License for more details. # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software -# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, +# MA 02110-1335, USA. #===================================================================== # # this is the default code for the Check package # #===================================================================== +use strict; sub init { my $self = shift; - %{ $self->{numbername} } = - (0 => 'Zero', - 1 => 'One', - 2 => 'Two', - 3 => 'Three', - 4 => 'Four', - 5 => 'Five', - 6 => 'Six', - 7 => 'Seven', - 8 => 'Eight', - 9 => 'Nine', - 10 => 'Ten', - 11 => 'Eleven', - 12 => 'Twelve', - 13 => 'Thirteen', - 14 => 'Fourteen', - 15 => 'Fifteen', - 16 => 'Sixteen', - 17 => 'Seventeen', - 18 => 'Eighteen', - 19 => 'Nineteen', - 20 => 'Twenty', - 30 => 'Thirty', - 40 => 'Forty', - 50 => 'Fifty', - 60 => 'Sixty', - 70 => 'Seventy', - 80 => 'Eighty', - 90 => 'Ninety', - 10**2 => 'Hundred', - 10**3 => 'Thousand', - 10**6 => 'Million', - 10**9 => 'Billion', - 10**12 => 'Trillion', - ); + %{ $self->{numbername} } = (0 => 'Zero', + 1 => 'One', + 2 => 'Two', + 3 => 'Three', + 4 => 'Four', + 5 => 'Five', + 6 => 'Six', + 7 => 'Seven', + 8 => 'Eight', + 9 => 'Nine', + 10 => 'Ten', + 11 => 'Eleven', + 12 => 'Twelve', + 13 => 'Thirteen', + 14 => 'Fourteen', + 15 => 'Fifteen', + 16 => 'Sixteen', + 17 => 'Seventeen', + 18 => 'Eighteen', + 19 => 'Nineteen', + 20 => 'Twenty', + 30 => 'Thirty', + 40 => 'Forty', + 50 => 'Fifty', + 60 => 'Sixty', + 70 => 'Seventy', + 80 => 'Eighty', + 90 => 'Ninety', + 10**2 => 'Hundred', + 10**3 => 'Thousand', + 10**6 => 'Million', + 10**9 => 'Billion', + 10**12 => 'Trillion',); } - sub num2text { my ($self, $amount) = @_; @@ -90,79 +89,80 @@ sub num2text { while (@num) { @a = (); - for (1 .. 3) { - push @a, shift @num; + for (1..3) { + push(@a, shift(@num)); } - push @numblock, join / /, reverse @a; + push(@numblock, join(" ", reverse @a)); } - + while (@numblock) { - $i = $#numblock; - @num = split //, $numblock[$i]; - + $i = $#numblock; + @num = split(//, $numblock[$i]); + if ($numblock[$i] == 0) { pop @numblock; next; } - + if ($numblock[$i] > 99) { + # the one from hundreds - push @textnumber, $self->{numbername}{$num[0]}; - + push(@textnumber, $self->{numbername}{ $num[0] }); + # add hundred designation - push @textnumber, $self->{numbername}{10**2}; + push(@textnumber, $self->{numbername}{ 10**2 }); # reduce numblock $numblock[$i] -= $num[0] * 100; - + } - + $numblock[$i] *= 1; - + if ($numblock[$i] > 9) { + # tens - push @textnumber, $self->format_ten($numblock[$i]); + push(@textnumber, $self->format_ten($numblock[$i])); } elsif ($numblock[$i] > 0) { + # ones - push @textnumber, $self->{numbername}{$numblock[$i]}; + push(@textnumber, $self->{numbername}{ $numblock[$i] }); } - + # add thousand, million if ($i) { - $num = 10**($i * 3); - push @textnumber, $self->{numbername}{$num}; + my $num = 10**($i * 3); + push(@textnumber, $self->{numbername}{$num}); } - - pop @numblock; - + + pop(@numblock); + } - join ' ', @textnumber; + join(' ', @textnumber); } - sub format_ten { my ($self, $amount) = @_; - + my $textnumber = ""; - my @num = split //, $amount; + my @num = split(//, $amount); if ($amount > 20) { - $textnumber = $self->{numbername}{$num[0]*10}; - $amount = $num[1]; + $textnumber = $self->{numbername}{ $num[0] * 10 }; + $amount = $num[1]; } else { $textnumber = $self->{numbername}{$amount}; - $amount = 0; + $amount = 0; } - $textnumber .= " ".$self->{numbername}{$amount} if $amount; + $textnumber .= " " . $self->{numbername}{$amount} if $amount; $textnumber; - -} +} 1;