Skip to content

Commit

Permalink
Bugfix: Decimal incorrectly minified 139.9 to 230 instead of 140
Browse files Browse the repository at this point in the history
  • Loading branch information
tdewolff committed Jan 12, 2020
1 parent 0c951d4 commit 70870d2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
7 changes: 5 additions & 2 deletions common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 2 additions & 0 deletions common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 70870d2

Please sign in to comment.