diff --git a/common.go b/common.go index ee1879e746..17787f0839 100644 --- a/common.go +++ b/common.go @@ -156,12 +156,15 @@ func Decimal(num []byte, prec int) []byte { break } else if inc && i < dot { // end inc for integer num[i] = '0' - break } else if !inc && (i < dot || num[i] != '0') { break } } - end = i + 1 + if i < dot { + end = dot + } else { + end = i + 1 + } if inc { if dot == start && end == start+1 { diff --git a/common_test.go b/common_test.go index e1dd3bf530..46f932b3c7 100644 --- a/common_test.go +++ b/common_test.go @@ -134,6 +134,7 @@ func TestDecimalTruncate(t *testing.T) { {"100000000000009", 15, "100000000000009"}, {"1000000000000009", 15, "1000000000000009"}, {"10000000000000009", 15, "10000000000000009"}, + {"139.99999999", 8, "140"}, } for _, tt := range numberTests { t.Run(tt.number, func(t *testing.T) { @@ -289,6 +290,7 @@ func TestNumberTruncate(t *testing.T) { {".3333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333397e-903", 0, ".3333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333397e-903"}, {"29.629775e-9", 0, ".29629775e-7"}, {"e-9223372036854775808", 0, "e-9223372036854775808"}, + {"139.99999999", 8, "140"}, } for _, tt := range numberTests { t.Run(tt.number, func(t *testing.T) {