From 57426b3565a9647b907fb430dbf17bb7c8775d88 Mon Sep 17 00:00:00 2001 From: alfred-mk Date: Wed, 2 Jul 2025 09:29:56 +0300 Subject: [PATCH] use the TruncateDecimalString to format the displayed balance --- handlers/application/menuhandler.go | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/handlers/application/menuhandler.go b/handlers/application/menuhandler.go index 0effbec..426fcef 100644 --- a/handlers/application/menuhandler.go +++ b/handlers/application/menuhandler.go @@ -3,7 +3,6 @@ package application import ( "bytes" "context" - "errors" "fmt" "path" "strconv" @@ -1504,17 +1503,14 @@ func loadUserContent(ctx context.Context, activeSym string, balance string, alia l := gotext.NewLocale(translationDir, code) l.AddDomain("default") - balFloat, err := strconv.ParseFloat(balance, 64) + // Format the balance to 2 decimal places or default to 0.00 + formattedAmount, err := store.TruncateDecimalString(balance, 2) if err != nil { - //Only exclude ErrSyntax error to avoid returning an error if the active bal is not available yet - if !errors.Is(err, strconv.ErrSyntax) { - logg.ErrorCtxf(ctx, "failed to parse activeBal as float", "value", balance, "error", err) - return "", err - } - balFloat = 0.00 + formattedAmount = "0.00" } - // Format to 2 decimal places - balStr := fmt.Sprintf("%.2f %s", balFloat, activeSym) + + // format the final output + balStr := fmt.Sprintf("%s %s", formattedAmount, activeSym) if alias != "" { content = l.Get("%s balance: %s\n", alias, balStr) } else {