Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 1980cae2

Von Sven Schöling vor fast 3 Jahren hinzugefügt

  • ID 1980cae2fc761885bbe2791bea0e19a99de30f4e
  • Vorgänger b3d44367
  • Nachfolger 806f9dd3

Number: Konvertierung in Basiseinheit für format_number_units

Unterschiede anzeigen:

SL/Helper/Number.pm
3 3
use strict;
4 4
use Exporter qw(import);
5 5
use List::Util qw(max min);
6
use List::UtilsBy qw(rev_nsort_by);
6 7
use Config;
7 8

  
8 9
our @EXPORT_OK = qw(
......
60 61
    return _format_number($amount, $places, %params);
61 62
  }
62 63

  
63
  $amount       *= $unit_from->convert_to(1, $unit_to);
64
  $amount       *= $unit_from->factor;
64 65

  
65
  my $conv_units = $unit_from->convertible_units($all_units);
66
  # unline AM::convertible_uits, this one doesn't sort by default
67
  my @conv_units = rev_nsort_by { $_->factor // 0 } @{ $unit_from->convertible_units($all_units) };
66 68

  
67
  if (!scalar @{ $conv_units }) {
69
  if (!scalar @conv_units) {
68 70
    return _format_number($amount, $places, %params) . " " . $unit_to->name;
69 71
  }
70 72

  
71 73
  my @values;
72 74
  my $num;
73 75

  
74
  for my $unit (@$conv_units) {
76
  for my $unit (@conv_units) {
75 77
    my $last = $unit->name eq $unit_to->name;
76 78
    if (!$last) {
77 79
      $num     = int($amount / $unit->factor);

Auch abrufbar als: Unified diff