Commit 46526221 authored by David Vickrey's avatar David Vickrey Committed by Dave Watson

Add control of floating point serialization to JSON serialization

Summary: Title.  Note that this is a no-op with default parameters because folly::toAppend(double, &dest) calls folly::toAppend(double, &dest, DtoaMode, numDigits) with DtoaMode = SHORTEST and numDigits = 0.

Test Plan: Tested new functionality in D1212547.

Reviewed By: kelarini@fb.com

FB internal diff: D1212617
parent c8ad790f
......@@ -131,7 +131,7 @@ struct Printer {
throw std::runtime_error("folly::toJson: JSON object value was a "
"NaN or INF");
}
toAppend(v.asDouble(), &out_);
toAppend(v.asDouble(), &out_, opts_.double_mode, opts_.double_num_digits);
break;
case dynamic::INT64: {
auto intval = v.asInt();
......
......@@ -62,6 +62,8 @@ namespace json {
, sort_keys(false)
, skip_invalid_utf8(false)
, allow_nan_inf(false)
, double_mode(double_conversion::DoubleToStringConverter::SHORTEST)
, double_num_digits(0) // ignored when mode is SHORTEST
{}
// If true, keys in an object can be non-strings. (In strict
......@@ -97,6 +99,11 @@ namespace json {
// true to allow NaN or INF values
bool allow_nan_inf;
// Options for how to print floating point values. See Conv.h
// toAppend implementation for floating point for more info
double_conversion::DoubleToStringConverter::DtoaMode double_mode;
unsigned int double_num_digits;
};
/*
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment