X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Fsupport%2Flstrings.cpp;h=6faf1a4fc3fd25838adb3b8c52c390315f569578;hb=c9d9309c1ecffa218dee04ce4f7991ed4fc0c9bb;hp=c77c986227dc60b981acd1e87230bbb75ef72a3e;hpb=2a8db0a64bd40ed1c91ab93297cb0fff78f71bde;p=features.git diff --git a/src/support/lstrings.cpp b/src/support/lstrings.cpp index c77c986227..6faf1a4fc3 100644 --- a/src/support/lstrings.cpp +++ b/src/support/lstrings.cpp @@ -1407,6 +1407,10 @@ std::string formatFPNumber(double x) os << std::fixed; // Prevent outputs of 23.4200000000000017 but output small numbers // with at least 6 significant digits. + bool const neg = x < 0; + // Treat all doubles as positive for the formatting + if (neg) + x = -x; double const logarithm = log10(x); os << std::setprecision(max(6 - static_cast(round(logarithm)), 0)) << x; string result = os.str(); @@ -1415,6 +1419,9 @@ std::string formatFPNumber(double x) if (result[result.length()-1] == '.') result = rtrim(result, "."); } + // Re-add negativity + if (neg) + result = "-" + result; return result; }