Fixed json/toml float precision on write

This commit is contained in:
MihailRis 2023-12-03 04:27:43 +03:00
parent 209acd257c
commit f47882194c
2 changed files with 8 additions and 1 deletions

View File

@ -2,6 +2,7 @@
#include <math.h>
#include <sstream>
#include <iomanip>
#include <memory>
#include "commons.h"
@ -70,6 +71,8 @@ void stringify(Value* value,
} else if (value->type == valtype::boolean) {
ss << (value->value.boolean ? "true" : "false");
} else if (value->type == valtype::number) {
ss << std::fixed;
ss << std::setprecision(15);
ss << value->value.decimal;
} else if (value->type == valtype::integer) {
ss << value->value.integer;

View File

@ -3,6 +3,7 @@
#include <math.h>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <assert.h>
@ -96,7 +97,10 @@ std::string Wrapper::write() const {
break;
case fieldtype::ftint: ss << *((int*)field->ptr); break;
case fieldtype::ftuint: ss << *((uint*)field->ptr); break;
case fieldtype::ftfloat: ss << *((float*)field->ptr); break;
case fieldtype::ftfloat:
ss << std::fixed;
ss << std::setprecision(15);
ss << *((float*)field->ptr); break;
case fieldtype::ftstring:
ss << escape_string(*((const string*)field->ptr));
break;