use the TruncateDecimalString to format the displayed balance

This commit is contained in:
Alfred Kamanda 2025-07-02 09:29:56 +03:00
parent b42dec8373
commit 57426b3565
Signed by: Alfred-mk
GPG Key ID: 7EA3D01708908703

View File

@ -3,7 +3,6 @@ package application
import ( import (
"bytes" "bytes"
"context" "context"
"errors"
"fmt" "fmt"
"path" "path"
"strconv" "strconv"
@ -1504,17 +1503,14 @@ func loadUserContent(ctx context.Context, activeSym string, balance string, alia
l := gotext.NewLocale(translationDir, code) l := gotext.NewLocale(translationDir, code)
l.AddDomain("default") 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 { if err != nil {
//Only exclude ErrSyntax error to avoid returning an error if the active bal is not available yet formattedAmount = "0.00"
if !errors.Is(err, strconv.ErrSyntax) {
logg.ErrorCtxf(ctx, "failed to parse activeBal as float", "value", balance, "error", err)
return "", err
} }
balFloat = 0.00
} // format the final output
// Format to 2 decimal places balStr := fmt.Sprintf("%s %s", formattedAmount, activeSym)
balStr := fmt.Sprintf("%.2f %s", balFloat, activeSym)
if alias != "" { if alias != "" {
content = l.Get("%s balance: %s\n", alias, balStr) content = l.Get("%s balance: %s\n", alias, balStr)
} else { } else {