convertPreciseToDecimal converts the precise integer amount to a decimal value by dividing by precision, storing the exact string representation
(transaction *Transaction)
| 345 | // convertPreciseToDecimal converts the precise integer amount to a decimal value |
| 346 | // by dividing by precision, storing the exact string representation |
| 347 | func convertPreciseToDecimal(transaction *Transaction) { |
| 348 | // Use the decimal package for exact decimal arithmetic |
| 349 | preciseAmountStr := transaction.PreciseAmount.String() |
| 350 | preciseAmountDec, _ := decimal.NewFromString(preciseAmountStr) |
| 351 | |
| 352 | // Create decimal for precision |
| 353 | precisionDec := decimal.NewFromFloat(transaction.Precision) |
| 354 | |
| 355 | // Perform division with exact decimal arithmetic |
| 356 | resultDec := preciseAmountDec.Div(precisionDec) |
| 357 | |
| 358 | // Store the exact string representation |
| 359 | transaction.AmountString = resultDec.String() |
| 360 | |
| 361 | // Also store the float64 for backward compatibility |
| 362 | // This may still have precision issues but is kept for existing code |
| 363 | transaction.Amount, _ = resultDec.Float64() |
| 364 | } |
| 365 | |
| 366 | // convertDecimalToPrecise converts a decimal amount to precise integer |
| 367 | // by multiplying by precision |
no outgoing calls
no test coverage detected