diff --git a/lib/Travelynx.pm b/lib/Travelynx.pm index b08593f..0f7b289 100755 --- a/lib/Travelynx.pm +++ b/lib/Travelynx.pm @@ -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 ) = @_; diff --git a/templates/journey.html.ep b/templates/journey.html.ep index d138126..f5eebfc 100644 --- a/templates/journey.html.ep +++ b/templates/journey.html.ep @@ -130,8 +130,8 @@ <%= numify_skipped_stations($journey->{skip_route}) %>
% } % 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 { ?