diff --git a/numeric.go b/numeric.go index b5caa41..c654542 100644 --- a/numeric.go +++ b/numeric.go @@ -448,11 +448,8 @@ func (src *Numeric) toFloat64() (float64, error) { return math.Inf(-1), nil } - switch { - case src.Exp == 0: + if src.Exp == 0 { return float64(src.Int.Int64()), nil - case src.Exp == 1: - return float64(src.Int.Int64() * 10), nil } buf := make([]byte, 0, 32) diff --git a/numeric_test.go b/numeric_test.go index 3e97405..6e8a8c5 100644 --- a/numeric_test.go +++ b/numeric_test.go @@ -445,20 +445,23 @@ func TestNumericSmallNegativeValues(t *testing.T) { } // https://github.com/jackc/pgtype/issues/210 -func TestNumericFloat64(t *testing.T) { - n := pgtype.Numeric{ - Int: big.NewInt(5), - Exp: 1, - Status: pgtype.Present, - } +func TestNumericFloat64FromIntegers(t *testing.T) { + for i := 0; i < 1024; i++ { + n := pgtype.Numeric{ + Int: big.NewInt(int64(i)), + Exp: 0, + Status: pgtype.Present, + } - var f float64 - err := n.AssignTo(&f) - if err != nil { - t.Fatal(err) - } + var got float64 + err := n.AssignTo(&got) + if err != nil { + t.Fatal(err) + } - if f != 50.0 { - t.Fatalf("expected %s, got %f", "50", f) + want := float64(i) + if got != want { + t.Fatalf("expected %d, got %f", i, got) + } } }