From: Sven Schöling Date: Fri, 17 Dec 2021 16:03:14 +0000 (+0100) Subject: Number: Konvertierung in Basiseinheit für format_number_units X-Git-Tag: kivitendo-mebil_0.1-0~10^2~2^2~216^2~29 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=f5d11325588b7b7c7bed5a3aaeeb5f842ad18b17;p=kivitendo-erp.git Number: Konvertierung in Basiseinheit für format_number_units --- diff --git a/SL/Helper/Number.pm b/SL/Helper/Number.pm index bf3b2b2cf..43b227819 100644 --- 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 List::UtilsBy qw(rev_nsort_by); use Config; our @EXPORT_OK = qw( @@ -60,18 +61,19 @@ sub _format_number_units { 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; - 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);