summaryrefslogtreecommitdiff
path: root/src/value.cc
diff options
context:
space:
mode:
authorMarius Kintel <marius@kintel.net>2012-01-09 00:44:01 (GMT)
committerMarius Kintel <marius@kintel.net>2012-01-09 00:44:01 (GMT)
commitad338d3e46eac0d0277a7000c48972d47f6c0091 (patch)
tree60c7a1d008cc89f9dc88ec905e4c9d8b548ffd74 /src/value.cc
parentd3c9654ed5cfed4f03b51f7f1ef14e521b26d446 (diff)
Another try at fixing double-to-text conversion for testing
Diffstat (limited to 'src/value.cc')
-rw-r--r--src/value.cc10
1 files changed, 8 insertions, 2 deletions
diff --git a/src/value.cc b/src/value.cc
index c9440ae..47fac1e 100644
--- a/src/value.cc
+++ b/src/value.cc
@@ -368,11 +368,17 @@ std::string Value::toString() const
// across platforms for testing purposes.
{
std::stringstream tmp;
- tmp.precision(16);
+ tmp.precision(12);
tmp.setf(std::ios_base::fixed);
tmp << this->num;
std::string tmpstr = tmp.str();
- if (tmpstr.size() > 16) tmpstr.erase(16);
+ size_t endpos = tmpstr.find_last_not_of('0');
+ if (endpos >= 0 && tmpstr[endpos] == '.') endpos--;
+ tmpstr = tmpstr.substr(0, endpos+1);
+ size_t dotpos = tmpstr.find('.');
+ if (dotpos != std::string::npos) {
+ if (tmpstr.size() - dotpos > 12) tmpstr.erase(dotpos + 12);
+ }
stream << tmpstr;
}
#else
contact: Jan Huwald // Impressum