jackc / pgtype

MIT License
308 stars 110 forks source link

How can I get the float value of a pgtype.Numeric field? #130

Closed mathiasHillmann closed 2 years ago

mathiasHillmann commented 2 years ago

Is assignTo the only way to get the float value?

jackc commented 2 years ago

Yes. If you need more functionality you probably want to use the integration with the shopspring/decimal package. See https://github.com/jackc/pgx/wiki/Numeric-and-decimal-support.

mathiasHillmann commented 2 years ago

In the end I created this util function for my needs:

func NumericToFloat(src pgtype.Numeric) float64 {
    var temp float64
    src.AssignTo(&temp)
    return temp
}