mirror of
https://github.com/shopspring/decimal.git
synced 2024-11-22 12:30:49 +01:00
Fix possible int64 overflow and remove unnecessary code
This commit is contained in:
parent
669901768e
commit
632e313f4a
2 changed files with 8 additions and 2 deletions
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in a new issue