From 23463c4b962a784b7ece449b0f9343eb315f9617 Mon Sep 17 00:00:00 2001 From: GenevensiS <66968533+G-e-n-e-v-e-n-s-i-S@users.noreply.github.com> Date: Sun, 24 May 2026 16:14:13 +0200 Subject: [PATCH] don't print scientific notation in to_json --- src/script/functions/json.cpp | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/script/functions/json.cpp b/src/script/functions/json.cpp index 96d0a4ba..c9a17a8e 100644 --- a/src/script/functions/json.cpp +++ b/src/script/functions/json.cpp @@ -33,7 +33,7 @@ // ----------------------------------------------------------------------------- : 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_; 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::int64: - case boost::json::kind::double_: os << jv; 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_: if(jv.get_bool()) os << "true";