Handle null values in numeric
This commit is contained in:
parent
cbda69e827
commit
04fd687324
@ -7,6 +7,9 @@ type Numeric struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (n Numeric) GetFloat64() float64 {
|
func (n Numeric) GetFloat64() float64 {
|
||||||
|
if n.Status != pgtype.Present {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
var balance float64
|
var balance float64
|
||||||
err := n.AssignTo(&balance)
|
err := n.AssignTo(&balance)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -16,11 +19,17 @@ func (n Numeric) GetFloat64() float64 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (n Numeric) GetPositive() bool {
|
func (n Numeric) GetPositive() bool {
|
||||||
|
if n.Status != pgtype.Present {
|
||||||
|
return true
|
||||||
|
}
|
||||||
float := n.GetFloat64()
|
float := n.GetFloat64()
|
||||||
return float >= 0
|
return float >= 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n Numeric) IsZero() bool {
|
func (n Numeric) IsZero() bool {
|
||||||
|
if n.Status != pgtype.Present {
|
||||||
|
return true
|
||||||
|
}
|
||||||
float := n.GetFloat64()
|
float := n.GetFloat64()
|
||||||
return float == 0
|
return float == 0
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user