Handle null values in numeric

This commit is contained in:
Jan Bader 2021-12-07 21:00:22 +00:00
parent cbda69e827
commit 04fd687324

View File

@ -7,6 +7,9 @@ type Numeric struct {
}
func (n Numeric) GetFloat64() float64 {
if n.Status != pgtype.Present {
return 0
}
var balance float64
err := n.AssignTo(&balance)
if err != nil {
@ -16,11 +19,17 @@ func (n Numeric) GetFloat64() float64 {
}
func (n Numeric) GetPositive() bool {
if n.Status != pgtype.Present {
return true
}
float := n.GetFloat64()
return float >= 0
}
func (n Numeric) IsZero() bool {
if n.Status != pgtype.Present {
return true
}
float := n.GetFloat64()
return float == 0
}