diff --git a/src/utils/conversions.go b/src/utils/conversions.go new file mode 100644 index 0000000..5d86ac4 --- /dev/null +++ b/src/utils/conversions.go @@ -0,0 +1,13 @@ +package utils + +import ( + "strings" +) + +func ConvertLocalizedString(s string) string { + if strings.ContainsAny(s, ",") { + return strings.Replace(s, ",", ".", 1) + } else { + return s + } +} diff --git a/src/widgets/proc_freebsd.go b/src/widgets/proc_freebsd.go index 96c8833..dc4399b 100644 --- a/src/widgets/proc_freebsd.go +++ b/src/widgets/proc_freebsd.go @@ -1,5 +1,3 @@ -// +build freebsd - package widgets import ( @@ -9,6 +7,8 @@ import ( "os/exec" "strconv" "strings" + + "github.com/cjbassi/gotop/src/utils" ) type processList struct { @@ -44,11 +44,11 @@ func getProcs() ([]Proc, error) { if err != nil { log.Printf("failed to convert first field to int: %v. split: %v", err, process) } - cpu, err := strconv.ParseFloat(process.Cpu, 64) + cpu, err := strconv.ParseFloat(utils.ConvertLocalizedString(process.Cpu), 32) if err != nil { log.Printf("failed to convert third field to float: %v. split: %v", err, process) } - mem, err := strconv.ParseFloat(process.Mem, 64) + mem, err := strconv.ParseFloat(utils.ConvertLocalizedString(process.Mem), 32) if err != nil { log.Printf("failed to convert fourth field to float: %v. split: %v", err, process) }