From 741cd60b1bd4bd4940e4813a1b301cc864647dd8 Mon Sep 17 00:00:00 2001 From: Emir Beganovic Date: Sun, 5 May 2019 11:24:26 +0400 Subject: [PATCH 1/2] Add test for keeping float precision --- main_test.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/main_test.go b/main_test.go index 1fa38b98..b3e87831 100644 --- a/main_test.go +++ b/main_test.go @@ -1164,6 +1164,20 @@ func TestCountWithQueryOption(t *testing.T) { } } +func TestFloatColumnPrecision(t *testing.T) { + type FloatTest struct { + ID string `gorm:"primary_key"` + FloatValue float64 `gorm:"column:float_value" sql:"type:float(255,5);"` + } + DB.DropTable(&FloatTest{}) + DB.AutoMigrate(&FloatTest{}) + + data := FloatTest{ID: "uuid", FloatValue: 112.57315} + if err := DB.Save(&data).Error; err != nil || data.ID != "uuid" || data.FloatValue != 112.57315 { + t.Errorf("Float value should not lose precision") + } +} + func BenchmarkGorm(b *testing.B) { b.N = 2000 for x := 0; x < b.N; x++ { From abe3fa8631a3726d37c4d3d497f6c1d2b698f90d Mon Sep 17 00:00:00 2001 From: Emir Beganovic Date: Sun, 5 May 2019 11:51:05 +0400 Subject: [PATCH 2/2] Run only on MySQL and sqlite --- main_test.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/main_test.go b/main_test.go index b3e87831..25b5940c 100644 --- a/main_test.go +++ b/main_test.go @@ -1165,6 +1165,10 @@ func TestCountWithQueryOption(t *testing.T) { } func TestFloatColumnPrecision(t *testing.T) { + if dialect := os.Getenv("GORM_DIALECT"); dialect != "mysql" && dialect != "sqlite" { + t.Skip() + } + type FloatTest struct { ID string `gorm:"primary_key"` FloatValue float64 `gorm:"column:float_value" sql:"type:float(255,5);"`