projects
/
kivitendo-erp.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
71450c6
)
Number: Konvertierung in Basiseinheit für format_number_units
author
Sven Schöling
<s.schoeling@googlemail.com>
Fri, 17 Dec 2021 16:03:14 +0000
(17:03 +0100)
committer
Jan Büren
<jan@kivitendo.de>
Mon, 14 Feb 2022 14:02:19 +0000
(15:02 +0100)
SL/Helper/Number.pm
patch
|
blob
|
history
diff --git
a/SL/Helper/Number.pm
b/SL/Helper/Number.pm
index
bf3b2b2
..
43b2278
100644
(file)
--- a/
SL/Helper/Number.pm
+++ b/
SL/Helper/Number.pm
@@
-3,6
+3,7
@@
package SL::Helper::Number;
use strict;
use Exporter qw(import);
use List::Util qw(max min);
use strict;
use Exporter qw(import);
use List::Util qw(max min);
+use List::UtilsBy qw(rev_nsort_by);
use Config;
our @EXPORT_OK = qw(
use Config;
our @EXPORT_OK = qw(
@@
-60,18
+61,19
@@
sub _format_number_units {
return _format_number($amount, $places, %params);
}
return _format_number($amount, $places, %params);
}
- $amount *= $unit_from->
convert_to(1, $unit_to)
;
+ $amount *= $unit_from->
factor
;
- my $conv_units = $unit_from->convertible_units($all_units);
+ # unline AM::convertible_uits, this one doesn't sort by default
+ my @conv_units = rev_nsort_by { $_->factor // 0 } @{ $unit_from->convertible_units($all_units) };
- if (!scalar @
{ $conv_units }
) {
+ if (!scalar @
conv_units
) {
return _format_number($amount, $places, %params) . " " . $unit_to->name;
}
my @values;
my $num;
return _format_number($amount, $places, %params) . " " . $unit_to->name;
}
my @values;
my $num;
- for my $unit (@
$
conv_units) {
+ for my $unit (@conv_units) {
my $last = $unit->name eq $unit_to->name;
if (!$last) {
$num = int($amount / $unit->factor);
my $last = $unit->name eq $unit_to->name;
if (!$last) {
$num = int($amount / $unit->factor);