Revision 97e3e9cd
Von Cem Aydin vor mehr als 2 Jahren hinzugefügt
SL/Helper/QrBillFunctions.pm | ||
---|---|---|
109 | 109 |
sub get_amount_formatted { |
110 | 110 |
$main::lxdebug->enter_sub(); |
111 | 111 |
|
112 |
unless ($_[0] =~ /^\d+\.\d{2}$/) { |
|
112 |
my $amount = $_[0]; |
|
113 |
|
|
114 |
# parameter should be a string containing a number |
|
115 |
# with 2 digits after the pointi'm also getting in the town |
|
116 |
unless ($amount =~ /^\d+\.\d{2}$/) { |
|
113 | 117 |
return undef; |
114 | 118 |
} |
115 | 119 |
|
116 |
local $_ = shift; |
|
117 |
$_ = reverse split //; |
|
118 |
m/^\d{2}\./g; |
|
119 |
s/\G(\d{3})(?=\d)/$1 /g; |
|
120 |
my $r = reverse $amount; |
|
121 |
# this matches the digits left of the '.' |
|
122 |
$r =~ m/^\d{2}\./g; |
|
123 |
# '\G' continuous the search where the last stopped, |
|
124 |
# matches three digits and substitutes with a space |
|
125 |
$r =~ s/\G(\d{3})(?=\d)/$1 /g; |
|
126 |
$r = reverse $r; |
|
120 | 127 |
|
121 | 128 |
$main::lxdebug->leave_sub(); |
122 |
return scalar reverse split //;
|
|
129 |
return $r;
|
|
123 | 130 |
} |
124 | 131 |
|
125 | 132 |
### internal functions |
Auch abrufbar als: Unified diff
Swiss QR-Bill: QrBillFunctions.pm Funktion get_amount_formatted vereinfacht / kommentiert