Skip to content

Commit

Permalink
Fix 1e-10 which was invalidly converted to .e-9, fixes #339
Browse files Browse the repository at this point in the history
  • Loading branch information
tdewolff committed Oct 15, 2020
1 parent 33619c7 commit 6b97531
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion common.go
Expand Up @@ -385,7 +385,7 @@ func Number(num []byte, prec int) []byte {
num[end] = '0'
end++
}
} else if normExp < -3 && lenNormExp < lenIntExp {
} else if normExp < -3 && lenNormExp < lenIntExp && dot < end {
// case 2: print normalized number (0.1 <= f < 1)
zeroes := -normExp + origExp
if 0 < zeroes {
Expand Down
5 changes: 5 additions & 0 deletions common_test.go
Expand Up @@ -165,7 +165,12 @@ func TestNumber(t *testing.T) {
{"0.001", ".001"},
{"0.0001", "1e-4"},
{"100e1", "1e3"},
{"1e10", "1e10"},
{"1e-10", "1e-10"},
{"1000e-7", "1e-4"},
{"1000e-6", ".001"},
{"1.1e+1", "11"},
{"1.1e-1", ".11"},
{"1.1e6", "11e5"},
{"1.1e", "1.1e"}, // broken number, don't parse
{"1.1e+", "1.1e+"}, // broken number, don't parse
Expand Down
2 changes: 2 additions & 0 deletions js/js_test.go
Expand Up @@ -26,6 +26,8 @@ func TestJS(t *testing.T) {
{`"use strict"`, `"use strict"`},
{`1.0`, `1`},
{`1000`, `1e3`},
{`1e10`, `1e10`},
{`1e-10`, `1e-10`},
{`0b1001`, `9`},
{`0o11`, `9`},
{`0x0D`, `13`},
Expand Down

0 comments on commit 6b97531

Please sign in to comment.