Skip to content

Commit

Permalink
fix : float64 nullish
Browse files Browse the repository at this point in the history
  • Loading branch information
sutantodadangfit committed Jun 20, 2023
1 parent 34f637e commit 89d8ad8
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions float.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ package nullish
import (
"bytes"
"database/sql/driver"
"encoding/binary"
"errors"
"math"

"github.com/goccy/go-json"
)
Expand Down Expand Up @@ -31,12 +33,24 @@ func (nf *NullFloat) Scan(value interface{}) error {
return nil
}

b, ok := value.(float64)
if !ok {
var res float64

switch t := value.(type) {

case []byte:

bits := binary.LittleEndian.Uint64(t)
res = math.Float64frombits(bits)

case float64:
res = t

default:
return errors.New("type assertion to float64 is failed")

}

nf.Float, nf.Valid = b, true
nf.Float, nf.Valid = res, true

return nil
}
Expand Down

0 comments on commit 89d8ad8

Please sign in to comment.