Skip to content

Commit

Permalink
Remove precision in as string...
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Charlot committed Mar 13, 2019
1 parent f941e3f commit fba35dd
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion cast.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func AsString(v interface{}) (string, bool) {
case int, int8, int16, int32, int64:
return strconv.FormatInt(reflect.ValueOf(d).Int(), 10), true
case float32, float64:
return strconv.FormatFloat(reflect.ValueOf(d).Float(), 'f', 2, 64), true
return strconv.FormatFloat(reflect.ValueOf(d).Float(), 'f', -1, 64), true
case uint, uint8, uint16, uint32, uint64:
return strconv.FormatUint(reflect.ValueOf(d).Uint(), 10), true
case json.Number:
Expand Down
4 changes: 2 additions & 2 deletions cast_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ func TestAsString(t *testing.T) {
testString(t, uint16(123), "123", true)
testString(t, uint32(123), "123", true)
testString(t, uint64(123), "123", true)
testString(t, float32(3.14501), "3.15", true)
testString(t, float64(3.14501), "3.15", true)
testString(t, float32(3.1), "3.0999999046325684", true)
testString(t, float64(3.14), "3.14", true)
testString(t, true, "true", true)
}

Expand Down

0 comments on commit fba35dd

Please sign in to comment.