From f5d11325588b7b7c7bed5a3aaeeb5f842ad18b17 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Sven=20Sch=C3=B6ling?= Date: Fri, 17 Dec 2021 17:03:14 +0100 Subject: [PATCH] =?utf8?q?Number:=20Konvertierung=20in=20Basiseinheit=20f?= =?utf8?q?=C3=BCr=20format=5Fnumber=5Funits?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- SL/Helper/Number.pm | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) 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); -- 2.20.1