1
0
mirror of https://github.com/json-iterator/go.git synced 2025-06-15 22:50:24 +02:00

demonstrate how to customize float encoding

This commit is contained in:
Tao Wen
2017-05-11 08:00:50 +08:00
parent 1df353727b
commit 3f1fcaff87
2 changed files with 41 additions and 4 deletions

View File

@ -34,9 +34,9 @@ func (stream *Stream) WriteFloat32(val float32) {
for p := precision - 1; p > 0 && fval < POW10[p]; p-- {
stream.writeByte('0')
}
stream.WriteUint64(fval);
stream.WriteUint64(fval)
for stream.buf[stream.n - 1] == '0' {
stream.n--;
stream.n--
}
}
@ -64,8 +64,8 @@ func (stream *Stream) WriteFloat64(val float64) {
for p := precision - 1; p > 0 && fval < POW10[p]; p-- {
stream.writeByte('0')
}
stream.WriteUint64(fval);
stream.WriteUint64(fval)
for stream.buf[stream.n - 1] == '0' {
stream.n--;
stream.n--
}
}