From b81bc2d57d85b472b249ae69ea9a29d9940cabd6 Mon Sep 17 00:00:00 2001 From: James Rich Date: Mon, 13 Apr 2026 12:30:44 -0500 Subject: [PATCH] fix(map): fix formatCoord to produce fixed decimal places instead of scientific notation --- .../feature/map/component/EditWaypointDialog.kt | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/feature/map/src/commonMain/kotlin/org/meshtastic/feature/map/component/EditWaypointDialog.kt b/feature/map/src/commonMain/kotlin/org/meshtastic/feature/map/component/EditWaypointDialog.kt index bcbc83624..ccea107ad 100644 --- a/feature/map/src/commonMain/kotlin/org/meshtastic/feature/map/component/EditWaypointDialog.kt +++ b/feature/map/src/commonMain/kotlin/org/meshtastic/feature/map/component/EditWaypointDialog.kt @@ -50,6 +50,7 @@ import org.meshtastic.core.resources.waypoint_edit import org.meshtastic.core.resources.waypoint_lock_to_my_node import org.meshtastic.core.resources.waypoint_new import org.meshtastic.feature.map.util.convertIntToEmoji +import kotlin.math.abs import org.maplibre.spatialk.geojson.Position as GeoPosition private const val MAX_NAME_LENGTH = 29 @@ -175,7 +176,12 @@ fun EditWaypointDialog( } /** Format a coordinate to 6 decimal places without using JVM-only String.format(). */ +@Suppress("MagicNumber") private fun Double.formatCoord(): String { - val rounded = (this * COORDINATE_PRECISION).toLong() / COORDINATE_PRECISION.toDouble() - return rounded.toString() + val negative = this < 0 + val absVal = abs(this) + val wholePart = absVal.toLong() + val fracPart = ((absVal - wholePart) * COORDINATE_PRECISION + 0.5).toLong() + val fracStr = fracPart.toString().padStart(6, '0') + return "${if (negative) "-" else ""}$wholePart.$fracStr" }