From 815466df970bd6666258aaf7feaa20209a79a473 Mon Sep 17 00:00:00 2001 From: Robin Tang Date: Mon, 17 Jun 2024 12:50:34 -0700 Subject: [PATCH] Checkpoint. --- lib/debezium/decimal.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/debezium/decimal.go b/lib/debezium/decimal.go index 793c4b814..9cccf6bdc 100644 --- a/lib/debezium/decimal.go +++ b/lib/debezium/decimal.go @@ -2,6 +2,7 @@ package debezium import ( "fmt" + "math" "math/big" "github.com/artie-labs/transfer/lib/typing/decimal" @@ -9,12 +10,13 @@ import ( // EncodeDecimal is used to encode a string representation of a number to `org.apache.kafka.connect.data.Decimal`. func EncodeDecimal(value string, scale int) ([]byte, error) { - scaledValue := new(big.Int).Exp(big.NewInt(10), big.NewInt(int64(scale)), nil) bigFloatValue := new(big.Float) if _, success := bigFloatValue.SetString(value); !success { return nil, fmt.Errorf("unable to use '%s' as a floating-point number", value) } - bigFloatValue.Mul(bigFloatValue, new(big.Float).SetInt(scaledValue)) + + scaledValue := big.NewFloat(math.Pow(10, float64(scale))) + bigFloatValue.Mul(bigFloatValue, scaledValue) // Extract the scaled integer value. bigIntValue, _ := bigFloatValue.Int(nil)