From c46f41e25f1a213e4d9ef0c0abcee2ee20f0256c Mon Sep 17 00:00:00 2001 From: alfred-mk Date: Fri, 29 Nov 2024 14:47:22 +0300 Subject: [PATCH] Format the balance to 2 decimal places --- internal/handlers/ussd/menuhandler.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/internal/handlers/ussd/menuhandler.go b/internal/handlers/ussd/menuhandler.go index dfd046d..bb0c9d8 100644 --- a/internal/handlers/ussd/menuhandler.go +++ b/internal/handlers/ussd/menuhandler.go @@ -811,7 +811,16 @@ func (h *Handlers) CheckBalance(ctx context.Context, sym string, input []byte) ( return res, err } - balStr := fmt.Sprintf("%s %s", activeBal, activeSym) + // Convert activeBal from []byte to float64 + balFloat, err := strconv.ParseFloat(string(activeBal), 64) + if err != nil { + logg.ErrorCtxf(ctx, "failed to parse activeBal as float", "value", string(activeBal), "error", err) + return res, err + } + + // Format to 2 decimal places + balStr := fmt.Sprintf("%.2f %s", balFloat, activeSym) + res.Content = l.Get("Balance: %s\n", balStr) return res, nil