mirror of
https://github.com/astaxie/beego.git
synced 2024-11-22 21:20:54 +00:00
string convert int fail use math/big fix #756
This commit is contained in:
parent
53e996d4c3
commit
5ceac1dd04
17
orm/utils.go
17
orm/utils.go
@ -16,6 +16,7 @@ package orm
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"math/big"
|
||||||
"reflect"
|
"reflect"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
@ -87,6 +88,14 @@ func (f StrTo) Int32() (int32, error) {
|
|||||||
// Int64 string to int64
|
// Int64 string to int64
|
||||||
func (f StrTo) Int64() (int64, error) {
|
func (f StrTo) Int64() (int64, error) {
|
||||||
v, err := strconv.ParseInt(f.String(), 10, 64)
|
v, err := strconv.ParseInt(f.String(), 10, 64)
|
||||||
|
if err != nil {
|
||||||
|
i := new(big.Int)
|
||||||
|
ni, ok := i.SetString(f.String(), 10) // octal
|
||||||
|
if !ok {
|
||||||
|
return int64(v), err
|
||||||
|
}
|
||||||
|
return ni.Int64(), nil
|
||||||
|
}
|
||||||
return int64(v), err
|
return int64(v), err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -117,6 +126,14 @@ func (f StrTo) Uint32() (uint32, error) {
|
|||||||
// Uint64 string to uint64
|
// Uint64 string to uint64
|
||||||
func (f StrTo) Uint64() (uint64, error) {
|
func (f StrTo) Uint64() (uint64, error) {
|
||||||
v, err := strconv.ParseUint(f.String(), 10, 64)
|
v, err := strconv.ParseUint(f.String(), 10, 64)
|
||||||
|
if err != nil {
|
||||||
|
i := new(big.Int)
|
||||||
|
ni, ok := i.SetString(f.String(), 10)
|
||||||
|
if !ok {
|
||||||
|
return uint64(v), err
|
||||||
|
}
|
||||||
|
return ni.Uint64(), nil
|
||||||
|
}
|
||||||
return uint64(v), err
|
return uint64(v), err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user