From e6d0597758f0397232ec04c4411e6443c9c0807f Mon Sep 17 00:00:00 2001 From: Thorsten Lanfer Date: Tue, 29 Mar 2022 00:37:06 +0200 Subject: [PATCH] handle numbers with decimals --- companion/adapter/inbound/streamlabs/streamlabs.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/companion/adapter/inbound/streamlabs/streamlabs.go b/companion/adapter/inbound/streamlabs/streamlabs.go index 296bf38..bb4e08e 100644 --- a/companion/adapter/inbound/streamlabs/streamlabs.go +++ b/companion/adapter/inbound/streamlabs/streamlabs.go @@ -63,13 +63,14 @@ func (s *streamlabs) Connect(events chan<- companion.StreamEvent, messages chan< err = client.On("event", func(c *gosocketio.Channel, data Ev) { if data.Type == "donation" { - amount := parseAmount(data.Message[0].Amount) * 100 + amount := parseAmount(data.Message[0].Amount) sourceCurrency := strings.ToLower(data.Message[0].Currency) if sourceCurrency != s.currency { converted := s.converter.Convert(int(amount), sourceCurrency, s.currency) log.Printf("Converted %v %v to %v %v", amount, sourceCurrency, converted, s.currency) amount = converted } + log.Println("Amount: ", amount) events <- companion.StreamEvent{ EventType: companion.EventTypeDono, Amount: amount, @@ -86,11 +87,11 @@ func (s *streamlabs) Connect(events chan<- companion.StreamEvent, messages chan< func parseAmount(input interface{}) int { asString := fmt.Sprint(input) - num, err := strconv.Atoi(asString) + num, err := strconv.ParseFloat(asString, 32) if err != nil { return -1 } - return num + return int(num * 100) } type Ev struct {