MCPcopy Create free account
hub / github.com/devaccuracy/ledgerforge / applyPrecisionLogic

Function applyPrecisionLogic

model/model.go:244–258  ·  view source on GitHub ↗

applyPrecisionLogic contains the core logic for converting amounts based on precision. It assumes transaction.Precision has been set appropriately before this call.

(transaction *Transaction)

Source from the content-addressed store, hash-verified

242// applyPrecisionLogic contains the core logic for converting amounts based on precision.
243// It assumes transaction.Precision has been set appropriately before this call.
244func applyPrecisionLogic(transaction *Transaction) *big.Int {
245 // Ensure precision is not zero to avoid division by zero, though ApplyPrecision and ApplyPrecisionWithDBLookup should handle this.
246 if transaction.Precision == 0 {
247 logrus.Warn("applyPrecisionLogic called with transaction.Precision = 0, defaulting to 1")
248 transaction.Precision = 1
249 }
250
251 if transaction.PreciseAmount != nil && transaction.PreciseAmount.Cmp(big.NewInt(0)) > 0 {
252 convertPreciseToDecimal(transaction)
253 return transaction.PreciseAmount
254 }
255
256 transaction.PreciseAmount = convertDecimalToPrecise(transaction)
257 return transaction.PreciseAmount
258}
259
260// fetchTransactionPrecisionFromDB is a placeholder for fetching precision from the database.
261// In a real application, this would query your database.

Callers 2

ApplyPrecisionFunction · 0.85

Calls 3

convertPreciseToDecimalFunction · 0.85
convertDecimalToPreciseFunction · 0.85
WarnMethod · 0.45

Tested by

no test coverage detected