Currently, when serializing a `Float value using to_string, the Printf.sprintf is used with the format hard-coded to "%.16g":
|
| `Float s -> Stream.scalar (scalar (Printf.sprintf "%.16g" s)) t |
In practice this results in the following:
# let x = 94.96 in
string_of_float x,
Printf.sprintf "%0.15g" x,
Printf.sprintf "%0.16g" x,
Yaml.to_string (`Float x);;
- : string * string * string * string Yaml.res =
("94.96", "94.96", "94.95999999999999", Ok "94.95999999999999\n")
Would it be possible introduce a way to control the float format precision? Alternatively, I propose hard-coding "%0.15g" would work better in terms of readability.
Note: of_json uses Stdlib.string_of_float, which itself uses "%0.12g" as the format.
Currently, when serializing a
`Floatvalue usingto_string, thePrintf.sprintfis used with the format hard-coded to"%.16g":ocaml-yaml/lib/yaml.ml
Line 94 in d126d94
In practice this results in the following:
Would it be possible introduce a way to control the float format precision? Alternatively, I propose hard-coding
"%0.15g"would work better in terms of readability.Note:
of_jsonusesStdlib.string_of_float, which itself uses"%0.12g"as the format.