Revision 7915128c
Von Moritz Bunkus vor mehr als 8 Jahren hinzugefügt
SL/Form.pm | ||
---|---|---|
982 | 982 |
# part. If an overflow occurs then apply that overflow to the part |
983 | 983 |
# before the decimal sign as well using integer arithmetic again. |
984 | 984 |
|
985 |
my $amount_str = sprintf '%.*f', $places + 10, abs($amount); |
|
985 |
my $int_amount = int(abs $amount); |
|
986 |
my $str_places = max(min(10, 16 - length("$int_amount") - $places), $places); |
|
987 |
my $amount_str = sprintf '%.*f', $places + $str_places, abs($amount); |
|
986 | 988 |
|
987 | 989 |
return $amount unless $amount_str =~ m{^(\d+)\.(\d+)$}; |
988 | 990 |
|
t/form/round_amount.t | ||
---|---|---|
57 | 57 |
is($::form->round_amount(198.90 * 0.75, 1), '149.2', '198.90 * 0.75 @ 1'); |
58 | 58 |
is($::form->round_amount(198.90 * 0.75, 0), '149', '198.90 * 0.75 @ 0'); |
59 | 59 |
|
60 |
is($::form->round_amount(19610.975, 2), '19610.98', '19610.975 @ 2'); |
|
61 |
|
|
60 | 62 |
# Negative values |
61 | 63 |
is($::form->round_amount(-1.05, 2), '-1.05', '-1.05 @ 2'); |
62 | 64 |
is($::form->round_amount(-1.05, 1), '-1.1', '-1.05 @ 1'); |
Auch abrufbar als: Unified diff
round_amount: Anzahl Stellen nicht zu hoch werden lassen