Skip to content

Commit 3368536

Browse files
committed
msgpack: add string() for decimal
Added a decimal type conversion function to a string, added tests for this function. Fixed name of function. Added #322
1 parent 782b626 commit 3368536

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

decimal/decimal.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ func decimalDecoder(d *msgpack.Decoder, v reflect.Value, extLen int) error {
156156
// For the general case, use shopspring/decimal.String().
157157
// For cases where it is known that numbers contain less than 26 characters,
158158
// you can use the optimized version.
159-
func (d Decimal) String() string {
159+
func (d Decimal) StringOptimized() string {
160160
coefficient := d.Decimal.Coefficient() // Note: In shopspring/decimal, the number is stored as coefficient *10^exponent, where exponent can be negative.
161161
exponent := d.Decimal.Exponent()
162162

decimal/decimal_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -770,7 +770,7 @@ func TestDecimalStringOptimized(t *testing.T) {
770770
dec, err := MakeDecimalFromString(tt.input)
771771
assert.NoError(t, err)
772772

773-
result := dec.String()
773+
result := dec.StringOptimized()
774774

775775
assert.Equal(t, tt.expected, result)
776776

@@ -802,8 +802,8 @@ func TestTarantoolBCDCompatibility(t *testing.T) {
802802
err = dec2.UnmarshalMsgpack(msgpackData)
803803
assert.NoError(t, err)
804804

805-
originalStr := dec.String()
806-
roundtripStr := dec2.String()
805+
originalStr := dec.StringOptimized()
806+
roundtripStr := dec2.StringOptimized()
807807

808808
assert.Equal(t, originalStr, roundtripStr,
809809
"BCD roundtrip failed for input: %s", input)

0 commit comments

Comments
 (0)