journey: show distances below 10km with 100m resolution (and <1km with 1m)

This commit is contained in:
Birte Kristina Friesel 2023-09-16 22:23:44 +02:00
parent 434eb5a18d
commit 04c8d7672a
No known key found for this signature in database
GPG key ID: 19E6E524EBB177BA
2 changed files with 16 additions and 2 deletions

View file

@ -393,6 +393,20 @@ sub startup {
}
);
$self->helper(
'sprintf_km' => sub {
my ( $self, $km ) = @_;
if ( $km < 1 ) {
return sprintf( '%.f m', $km * 1000 );
}
if ( $km < 10 ) {
return sprintf( '%.1f km', $km );
}
return sprintf( '%.f km', $km );
}
);
$self->helper(
'load_icon' => sub {
my ( $self, $load ) = @_;

View file

@ -130,8 +130,8 @@
<%= numify_skipped_stations($journey->{skip_route}) %><br/>
% }
% if ($journey->{km_route} > 0.1) {
ca. <%= sprintf('%.f', $journey->{km_route}) %> km
(Luftlinie: <%= sprintf('%.f', $journey->{km_beeline}) %> km)
ca. <%= sprintf_km($journey->{km_route}) %>
(Luftlinie: <%= sprintf_km($journey->{km_beeline}) %>)
% }
% else {
?