From e1d1edee4348523efa8868b7d29d2d2e391673c5 Mon Sep 17 00:00:00 2001 From: nazar-kutz Date: Fri, 5 Mar 2021 20:05:05 +0200 Subject: [PATCH] remove zeros from time formatting --- .../src/main/java/net/osmand/util/Algorithms.java | 7 +++++++ OsmAnd/src/net/osmand/plus/OsmAndFormatter.java | 12 +++++++++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/OsmAnd-java/src/main/java/net/osmand/util/Algorithms.java b/OsmAnd-java/src/main/java/net/osmand/util/Algorithms.java index 36c0034a26..05da55a753 100644 --- a/OsmAnd-java/src/main/java/net/osmand/util/Algorithms.java +++ b/OsmAnd-java/src/main/java/net/osmand/util/Algorithms.java @@ -117,6 +117,13 @@ public class Algorithms { } return def; } + + public static String formatDoubleWithoutAdditionalZeros(double d) { + if(d == (long) d) + return String.format(Locale.US, "%d",(long)d); + else + return String.format("%s",d); + } public static int parseIntSilently(String input, int def) { if (input != null && input.length() > 0) { diff --git a/OsmAnd/src/net/osmand/plus/OsmAndFormatter.java b/OsmAnd/src/net/osmand/plus/OsmAndFormatter.java index 6a52fe9804..d18309730e 100644 --- a/OsmAnd/src/net/osmand/plus/OsmAndFormatter.java +++ b/OsmAnd/src/net/osmand/plus/OsmAndFormatter.java @@ -121,13 +121,19 @@ public class OsmAndFormatter { } public static String getFormattedTimeInterval(OsmandApplication app, double interval) { + String units; + double intervalInUnits; if (interval < 60) { - return interval + " " + app.getString(R.string.int_seconds); + units = app.getString(R.string.shared_string_sec); + intervalInUnits = interval; } else if (interval % 60 == 0) { - return (interval / 60) + " " + app.getString(R.string.int_min); + units = app.getString(R.string.int_min); + intervalInUnits = (interval / 60); } else { - return (interval / 60f) + " " + app.getString(R.string.int_min); + units = app.getString(R.string.int_min); + intervalInUnits = (interval / 60f); } + return Algorithms.formatDoubleWithoutAdditionalZeros(intervalInUnits) + " " + units; } public static String getFormattedDistanceInterval(OsmandApplication app, double interval) {