+std::string formatFPNumber(double x)
+{
+ // Need manual tweaking, QString::number(x, 'f', 16) does not work either
+ ostringstream os;
+ os << std::fixed;
+ // Prevent outputs of 23.4200000000000017 but output small numbers
+ // with at least 6 significant digits.
+ double const logarithm = log10(fabs(x));
+ os << std::setprecision(max(6 - iround(logarithm), 0)) << x;
+ string result = os.str();
+ if (result.find('.') != string::npos) {
+ result = rtrim(result, "0");
+ if (result[result.length()-1] == '.')
+ result = rtrim(result, ".");
+ }
+ return result;
+}
+
+