mirror of
https://github.com/shopspring/decimal.git
synced 2024-11-23 04:40:49 +01:00
feat: add uint64 surport
This commit is contained in:
parent
cd690d0c9e
commit
f778328e58
2 changed files with 163 additions and 148 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,2 +1,3 @@
|
||||||
.git
|
.git
|
||||||
*.swp
|
*.swp
|
||||||
|
.idea/
|
14
decimal.go
14
decimal.go
|
@ -87,6 +87,14 @@ func New(value int64, exp int32) Decimal {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewFromUint64 returns a new Decimal from a uint64, value * 10 ^ exp
|
||||||
|
func NewFromUint64(value uint64, exp int32) Decimal {
|
||||||
|
return Decimal{
|
||||||
|
value: new(big.Int).SetUint64(value),
|
||||||
|
exp: exp,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// NewFromBigInt returns a new Decimal from a big.Int, value * 10 ^ exp
|
// NewFromBigInt returns a new Decimal from a big.Int, value * 10 ^ exp
|
||||||
func NewFromBigInt(value *big.Int, exp int32) Decimal {
|
func NewFromBigInt(value *big.Int, exp int32) Decimal {
|
||||||
return Decimal{
|
return Decimal{
|
||||||
|
@ -988,6 +996,12 @@ func (d *Decimal) Scan(value interface{}) error {
|
||||||
*d = New(v, 0)
|
*d = New(v, 0)
|
||||||
return nil
|
return nil
|
||||||
|
|
||||||
|
case uint64:
|
||||||
|
// at least in clickhouse when the value is 0 in db, the data is sent
|
||||||
|
// to us as an uint64 instead of a int64 ...
|
||||||
|
*d = NewFromUint64(v, 0)
|
||||||
|
return nil
|
||||||
|
|
||||||
default:
|
default:
|
||||||
// default is trying to interpret value stored as string
|
// default is trying to interpret value stored as string
|
||||||
str, err := unquoteIfQuoted(v)
|
str, err := unquoteIfQuoted(v)
|
||||||
|
|
Loading…
Reference in a new issue