don't print scientific notation in to_json

This commit is contained in:
GenevensiS
2026-05-24 16:14:13 +02:00
parent 6f526a81f1
commit 23463c4b96
+16 -2
View File
@@ -33,7 +33,7 @@
// ----------------------------------------------------------------------------- : JSON to String // ----------------------------------------------------------------------------- : JSON to String
void pretty_print(std::ostream& os, const boost::json::value& jv, std::string* indent) void pretty_print(std::ostringstream& os, const boost::json::value& jv, std::string* indent)
{ {
std::string indent_; std::string indent_;
if(! indent) if(! indent)
@@ -94,10 +94,24 @@ void pretty_print(std::ostream& os, const boost::json::value& jv, std::string* i
case boost::json::kind::uint64: case boost::json::kind::uint64:
case boost::json::kind::int64: case boost::json::kind::int64:
case boost::json::kind::double_:
os << jv; os << jv;
break; break;
case boost::json::kind::double_: {
std::ostringstream oss;
oss << std::fixed << std::setprecision(10) << jv.as_double();
std::string str = oss.str();
// remove trailing zeros
if (str.find('.') != std::string::npos) {
str.erase(str.find_last_not_of('0') + 1);
if (str.back() == '.') {
str.pop_back();
}
}
os << str;
break;
}
case boost::json::kind::bool_: case boost::json::kind::bool_:
if(jv.get_bool()) if(jv.get_bool())
os << "true"; os << "true";