Float to JSON with specific format
I have a JSON object struct and there is only one specific float type member which I have to export to JSON with exactly one decimal digit after the comma ...
C like formatting "example": printf("%.1f", floatValue)
Is there any direct or indirect way to do this? (I mean with(in) jsoncpp feature set :) )
Yes, you have control of related settings when you configure a writer builder.
Note there's no comma. JSON has a defined format with no locale, so it's going to be a "." as the decimal separator.
https://github.com/open-source-parsers/jsoncpp/blob/master/src/lib_json/json_writer.cpp#L1162
(*settings)["precision"] = 17;
(*settings)["precisionType"] = "significant";
The "precisionType" setting can be "significant" or "decimal".
-
"significant" requests a "%.*g" format (this is the default)
-
"decimal" requests a "%.*f" format.