decimal
decimal copied to clipboard
How to convert a string to NullDecimal?
How to convert a string to NullDecimal? I use NullDecimal in gorm correspond to decimal(50,15) NOT NULL in mysql
Take a look in documentation, it's right in Overview section: https://pkg.go.dev/github.com/shopspring/decimal?utm_source=godoc#pkg-overview
The best way to create a new Decimal is to use decimal.NewFromString, ex:
n, err := decimal.NewFromString("-123.4567")
n.String() // output: "-123.4567"
Create NullDecimal from Decimal dec
:
nullD := decimal.NullDecimal{Valid: true, Decimal: dec}
Thanks for explaining this @edbond <3