You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix: parse float to string with precision to a sufficient level
fixes#989
The original implemetation uses fmt.Sprintf("%e", value) to convert
float to string, which will be truncated and rounded at the 6th decimal
point. For a float value that needs more precision (not arbitrary
precision), it's better to use strconv.FormatFloat with prec -1 to
achieve the smallest number of digits necessary such that ParseFloat
will return f exactly. Moreover, as fmt.Sprintf is for more general
purpose and strconv.FormatFloat is specifically for formatting a float,
the strconv.FormatFloat has better performance than fmt.Sprintf.
The benchmark test shows the strconv.FormatFloat takes 955.5 ns/op and
fmt.Sprintf takes 1961 ns/op.
Signed-off-by: Jude Hung <[email protected]>
0 commit comments