diff --git a/lib/typing/converters/string_converter.go b/lib/typing/converters/string_converter.go index 74a45fff..b44015d1 100644 --- a/lib/typing/converters/string_converter.go +++ b/lib/typing/converters/string_converter.go @@ -160,6 +160,8 @@ func (IntegerConverter) Convert(value any) (string, error) { return fmt.Sprint(BooleanToBit(parsedVal)), nil case int, int8, int16, int32, int64: return fmt.Sprint(parsedVal), nil + case *decimal.Decimal: + return parsedVal.String(), nil default: return "", fmt.Errorf("unexpected value: '%v', type: %T", value, value) } @@ -175,6 +177,8 @@ func (FloatConverter) Convert(value any) (string, error) { return Float64ToString(parsedVal), nil case int, int8, int16, int32, int64: return fmt.Sprint(parsedVal), nil + case *decimal.Decimal: + return parsedVal.String(), nil default: return "", fmt.Errorf("unexpected value: '%v', type: %T", value, value) } diff --git a/lib/typing/converters/string_converter_test.go b/lib/typing/converters/string_converter_test.go index ab15b037..2387759b 100644 --- a/lib/typing/converters/string_converter_test.go +++ b/lib/typing/converters/string_converter_test.go @@ -141,6 +141,12 @@ func TestFloatConverter_Convert(t *testing.T) { assert.NoError(t, err) assert.Equal(t, "123.45", val) } + { + // *decimal.Decimal + val, err := FloatConverter{}.Convert(decimal.NewDecimal(numbers.MustParseDecimal("123.45"))) + assert.NoError(t, err) + assert.Equal(t, "123.45", val) + } { // Integers for _, input := range []any{42, int8(42), int16(42), int32(42), int64(42), float32(42), float64(42)} { @@ -160,6 +166,12 @@ func TestIntegerConverter_Convert(t *testing.T) { assert.Equal(t, "42", parsedVal) } } + { + // Test decimal.Decimal + val, err := IntegerConverter{}.Convert(decimal.NewDecimal(numbers.MustParseDecimal("123"))) + assert.NoError(t, err) + assert.Equal(t, "123", val) + } { // Booleans {