Format big floats as well

This commit is contained in:
Dan Sosedoff 2016-01-07 20:10:53 -06:00
parent 3acc6febae
commit 28178e46de
2 changed files with 15 additions and 2 deletions

View File

@ -25,9 +25,18 @@ func (res *Result) PrepareBigints() {
continue
}
if reflect.TypeOf(col).Kind() == reflect.Int64 {
switch reflect.TypeOf(col).Kind() {
case reflect.Int64:
val := col.(int64)
if val < -9007199254740991 || val > 9007199254740991 {
res.Rows[i][j] = strconv.FormatInt(col.(int64), 10)
}
case reflect.Float64:
val := col.(float64)
if val < -999999999999999 || val > 999999999999999 {
res.Rows[i][j] = strconv.FormatFloat(val, 'e', -1, 64)
}
}
}
}
}

View File

@ -14,6 +14,8 @@ func Test_PrepareBigints(t *testing.T) {
Row{int(1234)},
Row{int64(9223372036854775807)},
Row{int64(-9223372036854775808)},
Row{float64(9223372036854775808.9223372036854775808)},
Row{float64(999999999999999.9)},
},
}
@ -22,6 +24,8 @@ func Test_PrepareBigints(t *testing.T) {
assert.Equal(t, 1234, result.Rows[0][0])
assert.Equal(t, "9223372036854775807", result.Rows[1][0])
assert.Equal(t, "-9223372036854775808", result.Rows[2][0])
assert.Equal(t, "9.223372036854776e+18", result.Rows[3][0])
assert.Equal(t, "9.999999999999999e+14", result.Rows[4][0])
}
func Test_CSV(t *testing.T) {