💄 Round transaction amount to keep 2 decimal places only

This commit is contained in:
LittleSheep 2025-01-29 20:18:29 +08:00
parent 9b5f67e677
commit 712ed6c2ae

View File

@ -2,6 +2,7 @@ package services
import ( import (
"fmt" "fmt"
"math"
"git.solsynth.dev/hypernet/passport/pkg/authkit" "git.solsynth.dev/hypernet/passport/pkg/authkit"
"git.solsynth.dev/hypernet/pusher/pkg/pushkit" "git.solsynth.dev/hypernet/pusher/pkg/pushkit"
@ -12,6 +13,9 @@ import (
) )
func MakeTransaction(amount float64, remark string, payer, payee *models.Wallet) (models.Transaction, error) { func MakeTransaction(amount float64, remark string, payer, payee *models.Wallet) (models.Transaction, error) {
// Round amount to keep 2 decimal places
amount = math.Round(amount*100) / 100
transaction := models.Transaction{ transaction := models.Transaction{
Amount: decimal.NewFromFloat(amount), Amount: decimal.NewFromFloat(amount),
Remark: remark, Remark: remark,