GORM是否有十进制数据类型来存储货币值( - > Decimal(8,2) )?
Decimal(8,2)
我在https://github.com/jinzhu/gorm#define-models-structs找不到它
我知道这有点老了,但我遇到了这个问题,很难找到答案 . 如果您使用Gqu with liquibase,请将BigDecimal用于任何浮点数 .
迈克尔的答案有效 . 但是如果你想使用golang的十进制类型,你可以像这样使用shopspring/decimal:
type TableName struct { Amount decimal.Decimal `json:"amount" sql:"type:decimal(20,8);"` }
如果您正在使用AutoMigrate,则可以给出GORM SQL instructions (in your struct model)如何构建表 . 尝试以下内容:
type Product struct { Id int ProductName string `sql:"type:varchar(250);"` Amount float32 `sql:"type:decimal(10,2);"` }
3 回答
我知道这有点老了,但我遇到了这个问题,很难找到答案 . 如果您使用Gqu with liquibase,请将BigDecimal用于任何浮点数 .
迈克尔的答案有效 . 但是如果你想使用golang的十进制类型,你可以像这样使用shopspring/decimal:
如果您正在使用AutoMigrate,则可以给出GORM SQL instructions (in your struct model)如何构建表 . 尝试以下内容: