fix(transaction): #151 float error | -17.49 parsed as -17.48
All checks were successful
Build Docker Image / Build-Docker-Image (push) Successful in 5m39s
Build and Push Docker Image / Build-And-Push-Docker-Image (push) Successful in 5m47s

This commit was merged in pull request #157.
This commit is contained in:
2025-06-07 13:36:27 +02:00
parent 79a1247bea
commit e65146c71c
2 changed files with 5 additions and 3 deletions

View File

@@ -2,6 +2,7 @@ package handler
import (
"fmt"
"math"
"net/http"
"spend-sparrow/internal/handler/middleware"
"spend-sparrow/internal/service"
@@ -193,7 +194,7 @@ func (h TransactionImpl) handleUpdateTransaction() http.HandlerFunc {
handleError(w, r, fmt.Errorf("could not parse value: %w", service.ErrBadRequest))
return
}
value := int64(valueF * service.DECIMALS_MULTIPLIER)
value := int64(math.Round(valueF * service.DECIMALS_MULTIPLIER))
timestamp, err := time.Parse("2006-01-02", r.FormValue("timestamp"))
if err != nil {

View File

@@ -3,6 +3,7 @@ package service
import (
"errors"
"fmt"
"math"
"spend-sparrow/internal/db"
"spend-sparrow/internal/log"
"spend-sparrow/internal/types"
@@ -465,7 +466,7 @@ func (s TransactionRecurringImpl) validateAndEnrichTransactionRecurring(
log.L.Error("transactionRecurring validate", "err", err)
return nil, fmt.Errorf("could not parse value: %w", ErrBadRequest)
}
valueInt := int64(valueFloat * DECIMALS_MULTIPLIER)
value := int64(math.Round(valueFloat * DECIMALS_MULTIPLIER))
if input.Party != "" {
err = validateString(input.Party, "party")
@@ -512,7 +513,7 @@ func (s TransactionRecurringImpl) validateAndEnrichTransactionRecurring(
AccountId: accountUuid,
TreasureChestId: treasureChestUuid,
Value: valueInt,
Value: value,
CreatedAt: createdAt,
CreatedBy: createdBy,