I'm using RapidJSON (https://github.com/miloyip/rapidjson) to create quite big arrays (~ 5 MB) and a lot of the space is waste due to too accurate floating point numbers. E.g.
StringBuffer s;
Writer<StringBuffer> writer(s);
writer.StartObject();
writer.String("value");
writer.Double(1.0/3.0);
writer.EndObject();
This results in a json "{'value': 0.33333333333}" which is very annoying when I only need a few significant numbers.
I found a solution Set floating point precision using rapidjson in this post, but it's already a few years old and outdated with the latest rapidjson build. Has anyone got a solution for this?
Use rapidjson::Writer::SetMaxDecimalPlaces http://rapidjson.org/classrapidjson_1_1_writer.html#aa7b6967dc237519e2a6d8b3939fb9634
writer.SetMaxDecimalPlaces(3);
writer.Double(1.0/3.0);