From f1f20455d20b0ba64c819c687bcb5611c2739885 Mon Sep 17 00:00:00 2001 From: Garth Vander Houwen Date: Sat, 17 Feb 2024 20:26:09 -0800 Subject: [PATCH] Make temp have no decimal places --- Meshtastic/Extensions/Float.swift | 4 +++- .../Views/Nodes/EnvironmentMetricsLog.swift | 16 ++++++++-------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/Meshtastic/Extensions/Float.swift b/Meshtastic/Extensions/Float.swift index 131c45e4..f85e4222 100644 --- a/Meshtastic/Extensions/Float.swift +++ b/Meshtastic/Extensions/Float.swift @@ -11,7 +11,9 @@ extension Float { func formattedTemperature() -> String { let temperature = Measurement(value: Double(self), unit: .celsius) - return temperature.formatted(.measurement(width: .narrow, usage: .weather)) + let mf = MeasurementFormatter() + mf.numberFormatter.maximumFractionDigits = 0 + return mf.string(from: temperature) } func localeTemperature() -> Double { let temperature = Measurement(value: Double(self), unit: .celsius) diff --git a/Meshtastic/Views/Nodes/EnvironmentMetricsLog.swift b/Meshtastic/Views/Nodes/EnvironmentMetricsLog.swift index 7abf4094..b20f873d 100644 --- a/Meshtastic/Views/Nodes/EnvironmentMetricsLog.swift +++ b/Meshtastic/Views/Nodes/EnvironmentMetricsLog.swift @@ -81,19 +81,19 @@ struct EnvironmentMetricsLog: View { Text(em.temperature.formattedTemperature()) } TableColumn("Humidity") { em in - Text("\(String(format: "%.2f", em.relativeHumidity))%") + Text("\(String(format: "%.0f", em.relativeHumidity))%") } TableColumn("Barometric Pressure") { em in - Text("\(String(format: "%.2f", em.barometricPressure)) hPa") + Text("\(String(format: "%.1f", em.barometricPressure)) hPa") } TableColumn("gas.resistance") { em in - Text("\(String(format: "%.2f", em.gasResistance)) ohms") + Text("\(String(format: "%.1f", em.gasResistance)) ohms") } TableColumn("current") { em in - Text("\(String(format: "%.2f", em.current))") + Text("\(String(format: "%.1f", em.current))") } TableColumn("voltage") { em in - Text("\(String(format: "%.2f", em.voltage))") + Text("\(String(format: "%.1f", em.voltage))") } TableColumn("timestamp") { em in Text(em.time?.formattedDate(format: dateFormatString) ?? "unknown.age".localized) @@ -134,11 +134,11 @@ struct EnvironmentMetricsLog: View { Text(em.temperature.formattedTemperature()) .font(.caption) - Text("\(String(format: "%.2f", em.relativeHumidity))%") + Text("\(String(format: "%.0f", em.relativeHumidity))%") .font(.caption) - Text("\(String(format: "%.2f", em.barometricPressure))") + Text("\(String(format: "%.1f", em.barometricPressure))") .font(.caption) - Text("\(String(format: "%.2f", em.gasResistance))") + Text("\(String(format: "%.1f", em.gasResistance))") .font(.caption) Text(em.time?.formattedDate(format: dateFormatString) ?? "unknown.age".localized) .font(.caption)