From a0393950167ed68c69c8320624a66ec1bc8863e7 Mon Sep 17 00:00:00 2001 From: Dustin Pianalto Date: Fri, 25 Mar 2022 15:30:46 -0800 Subject: [PATCH] Round floats to 1 decimal place --- internal/mqtt/event.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/internal/mqtt/event.go b/internal/mqtt/event.go index a4df632..f5e2f30 100644 --- a/internal/mqtt/event.go +++ b/internal/mqtt/event.go @@ -2,6 +2,7 @@ package mqtt import ( "fmt" + "math" "reflect" "strconv" "time" @@ -47,9 +48,9 @@ func eventToMap(event *weather.AmbientEntry) map[string]string { case uint, uint8, uint16, uint32, uint64: v = strconv.FormatUint(f.Uint(), 10) case float32: - v = strconv.FormatFloat(f.Float(), 'f', 4, 32) + v = strconv.FormatFloat(math.Round(f.Float()*10)/10, 'f', 4, 32) case float64: - v = strconv.FormatFloat(f.Float(), 'f', 4, 64) + v = strconv.FormatFloat(math.Round(f.Float()*10)/10, 'f', 4, 64) case []byte: v = string(f.Bytes()) case string: