Thanks Daniel and François for pointing out the RFC https://tools.ietf.org/html/rfc7159 and mentioning IEEE 754-2008 binary64. For my JSON parser I use Int64 to store integers and float to store decimal/floating point values. The tweak gives nice feature and helps with round-trip encoding/decoding. Since you mentioned the RFC and it states: "A JSON number such as 1E400 or 3.141592653589793238462643383279 may indicate potential interoperability problems, since it suggests that the software that created it expects receiving software to have greater capabilities for numeric magnitude and precision than is widely available." I will relax the condition for now. I used the benchmark provided by Milo Yip: https://github.com/miloyip/nativejson-benchmark/blob/master/data/roundtrip/roundtrip24.json Thanks, Viet On 1 August 2017 at 13:12, Daniel Bünzli wrote: > On 1 August 2017 at 12:47:37, Viet Le (vietlq85@gmail.com) wrote: > > > I haven't found precise limit, but as a rule of thumb (*not precise*), > for > > a positive float value to keep its precision, it *should* not be smaller > > than 1.00000000001e-312. To use JSON as precise serializer, it would be > > necessary to preserve accuracy. > > Here are a few tips: > > 1. The latest RFC recommends [1] to support the range of IEEE 754 double > precision numbers (those are OCaml's float) in JSON numbers. However since > you are converting your floating point representation from binary to a > decimal one you can't guarantee to round trip your floats with a JSON > number. > > 2. If you want to serialize precise integers with good interop you can do > so using JSON number if they are in the range [-2^53;2^53] (the range > written in the mentioned RFC seems wrong to me). Those are the integers a > double precision floating point numbers are able to represent precisely. > > 3. If you want to serialize precise floats you should do this as a JSON > string using a lossless textual notation for your binary floating point > number. Before OCaml 4.03 you can use this [2] function after 4.03 you can > use float_of_string and the "%h" format string [3]. > > Best, > > Daniel > > [1] https://tools.ietf.org/html/rfc7159#section-6 > [2] http://erratique.ch/software/gg/doc/Gg.Float.html#VALpp > [3] https://github.com/ocaml/ocaml/pull/268 > -- Kind regards, Viet