diff --git a/decimal.go b/decimal.go index bfb7699..8ae929e 100644 --- a/decimal.go +++ b/decimal.go @@ -86,11 +86,15 @@ func NewFromString(value string) (Decimal, error) { // Check if number is using scientific notation eIndex := strings.IndexAny(value, "Ee") if eIndex != -1 { - expInt, err := strconv.ParseInt(value[eIndex+1:len(value)], 10, 64) + expInt, err := strconv.ParseInt(value[eIndex+1:], 10, 32) if err != nil { + rerr := err.(*strconv.NumError) + if rerr.Err == strconv.ErrRange { + return Decimal{}, fmt.Errorf("can't convert %s to decimal: fractional part too long", value) + } return Decimal{}, fmt.Errorf("can't convert %s to decimal: exponent is not numeric", value) } - value = value[0:eIndex] + value = value[:eIndex] exp = expInt } diff --git a/decimal_test.go b/decimal_test.go index d9839b0..f8fff74 100644 --- a/decimal_test.go +++ b/decimal_test.go @@ -4,6 +4,7 @@ import ( "encoding/json" "encoding/xml" "math" + "strconv" "strings" "testing" "time" @@ -135,6 +136,7 @@ func TestNewFromStringErrs(t *testing.T) { "123.456e1.3", "1e-1.2", "123.456e-1.3", + "123.456e" + strconv.FormatInt(math.MinInt64, 10), } for _, s := range tests {