mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Ensure full precision of doubles is saved to SQL.
std::iostream's operator<<(double) uses only 6 digits of precision by default. We want 12 digits when saving.
This commit is contained in:
parent
9db60ca63c
commit
537fd995a3
@ -31,6 +31,8 @@ extern "C"
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
|
||||
#include "gnc-sql-result.hpp"
|
||||
|
||||
struct GncSqlColumnInfo;
|
||||
@ -384,6 +386,22 @@ GncSqlColumnTableEntry::add_value_to_vec(QofIdTypeConst obj_name,
|
||||
}
|
||||
}
|
||||
|
||||
template <> inline void
|
||||
GncSqlColumnTableEntry::add_value_to_vec<double*>(QofIdTypeConst obj_name,
|
||||
const void* pObject,
|
||||
PairVec& vec, std::true_type) const
|
||||
{
|
||||
double* s = get_row_value_from_object<double*>(obj_name, pObject);
|
||||
|
||||
if (s != nullptr)
|
||||
{
|
||||
std::ostringstream stream;
|
||||
stream << std::setprecision(12) << std::fixed << *s;
|
||||
vec.emplace_back(std::make_pair(std::string{m_col_name}, stream.str()));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T> void
|
||||
GncSqlColumnTableEntry::add_value_to_vec(QofIdTypeConst obj_name,
|
||||
const void* pObject,
|
||||
@ -397,6 +415,19 @@ GncSqlColumnTableEntry::add_value_to_vec(QofIdTypeConst obj_name,
|
||||
return;
|
||||
}
|
||||
|
||||
template <> inline void
|
||||
GncSqlColumnTableEntry::add_value_to_vec<double>(QofIdTypeConst obj_name,
|
||||
const void* pObject,
|
||||
PairVec& vec, std::false_type) const
|
||||
{
|
||||
double s = *get_row_value_from_object<double*>(obj_name, pObject);
|
||||
|
||||
std::ostringstream stream;
|
||||
stream << std::setprecision(12) << std::fixed << s;
|
||||
vec.emplace_back(std::make_pair(std::string{m_col_name}, stream.str()));
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load an arbitrary object from a result row.
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user