Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does GORM have a Decimal datatype?

Tags:

go

go-gorm

Does GORM have a decimal datatype to store money values (-> Decimal(8,2))?

I could not find it on https://github.com/jinzhu/gorm#define-models-structs

like image 519
Martin Thoma Avatar asked Nov 27 '22 20:11

Martin Thoma


1 Answers

Michael's answer works. But If you want to use decimal type with golang, you can use shopspring/decimal like this:

type TableName struct {
  Amount    decimal.Decimal `json:"amount" sql:"type:decimal(20,8);"`
}
like image 76
Shinji Yamada Avatar answered Dec 23 '22 20:12

Shinji Yamada