From fe4cd35508c99b73e2a8c448447a155a10269fd0 Mon Sep 17 00:00:00 2001 From: Yaroslav Date: Tue, 11 Feb 2025 02:14:40 +0200 Subject: [PATCH] In some locales, the decimal point symbol is a comma instead of a period, and strconv fails to parse floats when commas are used as the decimal separator. --- main.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index a0da5ad..71ad5d2 100644 --- a/main.go +++ b/main.go @@ -1321,8 +1321,8 @@ func getProcessList() []ProcessMetrics { if len(fields) < 11 { continue } - cpu, _ := strconv.ParseFloat(fields[2], 64) - mem, _ := strconv.ParseFloat(fields[3], 64) + cpu, _ := strconv.ParseFloat(replaceCommas(fields[2]), 64) + mem, _ := strconv.ParseFloat(replaceCommas(fields[3]), 64) vsz, _ := strconv.ParseInt(fields[4], 10, 64) rss, _ := strconv.ParseInt(fields[5], 10, 64) pid, _ := strconv.Atoi(fields[1]) @@ -1337,6 +1337,10 @@ func getProcessList() []ProcessMetrics { return processes } +func replaceCommas(s string) string { + return strings.Replace(s, ",", ".", -1) +} + func updateTotalPowerChart(watts float64) { if watts > maxPowerSeen { maxPowerSeen = watts * 1.1