Skip to content

Commit e75bd84

Browse files
committed
msgpack: add string() for decimal
Added a benchmark, which shows that the code is optimized two or more times for string conversion than the code from the library. Added #322
1 parent bbd52ee commit e75bd84

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

decimal/decimal_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -893,3 +893,27 @@ func TestLargeNumberStringOptimized(t *testing.T) {
893893

894894
t.Logf("Large number handled via fallback: %s", optimized)
895895
}
896+
897+
func TestDecimalTrailingZeros(t *testing.T) {
898+
tests := []struct {
899+
input string
900+
expected string
901+
}{
902+
{"100.00", "100.00"},
903+
{"0.00", "0.00"},
904+
{"0.000", "0.000"},
905+
{"1.000", "1.000"},
906+
{"123.4500", "123.4500"},
907+
{"0.00100", "0.00100"},
908+
}
909+
910+
for _, tt := range tests {
911+
t.Run(tt.input, func(t *testing.T) {
912+
dec := MustMakeDecimal(tt.input)
913+
result := dec.StringOptimized()
914+
if result != tt.expected {
915+
t.Errorf("For %s: expected %s, got %s", tt.input, tt.expected, result)
916+
}
917+
})
918+
}
919+
}

0 commit comments

Comments
 (0)