Revision 65bc835d
Von Moritz Bunkus vor fast 14 Jahren hinzugefügt
SL/DB/Unit.pm | ||
---|---|---|
38 | 38 |
]; |
39 | 39 |
} |
40 | 40 |
|
41 |
sub base_factor { |
|
42 |
my ($self) = @_; |
|
43 |
|
|
44 |
if (!defined $self->{__base_factor}) { |
|
45 |
$self->{__base_factor} = !$self->base_unit || !$self->factor || ($self->name eq $self->base_unit) ? 1 : $self->factor * $self->base->base_factor; |
|
46 |
} |
|
47 |
|
|
48 |
return $self->{__base_factor}; |
|
49 |
} |
|
50 |
|
|
51 |
sub convert_to { |
|
52 |
my ($self, $qty, $other_unit) = @_; |
|
53 |
|
|
54 |
my $my_base_factor = $self->base_factor || 1; |
|
55 |
my $other_base_factor = $other_unit->base_factor || 1; |
|
56 |
|
|
57 |
return $qty * $my_base_factor / $other_base_factor; |
|
58 |
} |
|
59 |
|
|
41 | 60 |
1; |
Auch abrufbar als: Unified diff
Hilfsroutinen zum Umrechnen zwischen Einheiten