1
0
mirror of https://github.com/json-iterator/go.git synced 2025-06-24 23:16:47 +02:00

fix lossy float marshal and omit empty

This commit is contained in:
Tao Wen
2017-06-20 07:51:38 +08:00
parent 945fe53724
commit 39c9bb226a
2 changed files with 43 additions and 8 deletions

View File

@ -162,6 +162,17 @@ func Test_read_float_scientific(t *testing.T) {
should.Equal(float64(10), obj)
}
func Test_lossy_float_marshal(t *testing.T) {
should := require.New(t)
api := Config{MarshalFloatWith6Digits: true}.Froze()
output, err := api.MarshalToString(float64(0.1234567))
should.Nil(err)
should.Equal("0.123457", output)
output, err = api.MarshalToString(float32(0.1234567))
should.Nil(err)
should.Equal("0.123457", output)
}
func Benchmark_jsoniter_float(b *testing.B) {
b.ReportAllocs()
input := []byte(`1.1123,`)