You've already forked json-iterator
mirror of
https://github.com/json-iterator/go.git
synced 2025-06-18 22:57:33 +02:00
#68 float to int
This commit is contained in:
@ -43,5 +43,5 @@ func (decoder *FuzzyIntDecoder) Decode(ptr unsafe.Pointer, iter *jsoniter.Iterat
|
|||||||
default:
|
default:
|
||||||
iter.ReportError("FuzzyIntDecoder", "not number or string")
|
iter.ReportError("FuzzyIntDecoder", "not number or string")
|
||||||
}
|
}
|
||||||
*((*int)(ptr)) = iter.ReadInt()
|
*((*int)(ptr)) = int(iter.ReadFloat64())
|
||||||
}
|
}
|
||||||
|
@ -44,3 +44,10 @@ func Test_int_to_int(t *testing.T) {
|
|||||||
should.Nil(jsoniter.UnmarshalFromString(`100`, &val))
|
should.Nil(jsoniter.UnmarshalFromString(`100`, &val))
|
||||||
should.Equal(100, val)
|
should.Equal(100, val)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Test_float_to_int(t *testing.T) {
|
||||||
|
should := require.New(t)
|
||||||
|
var val int
|
||||||
|
should.Nil(jsoniter.UnmarshalFromString(`1.23`, &val))
|
||||||
|
should.Equal(1, val)
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user