Merge pull request #503 from meshtastic/2.2.24_Working_Changes

Make temp have no decimal places
This commit is contained in:
Garth Vander Houwen 2024-02-17 20:43:31 -08:00 committed by GitHub
commit f38d0d55d7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 11 additions and 9 deletions

View file

@ -11,7 +11,9 @@ extension Float {
func formattedTemperature() -> String {
let temperature = Measurement<UnitTemperature>(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<UnitTemperature>(value: Double(self), unit: .celsius)

View file

@ -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)