Skip to content
Snippets Groups Projects
Commit 9f2a50ff authored by Wuttke, Joachim's avatar Wuttke, Joachim Committed by Wuttke, Joachim
Browse files

further improve number display through regex

parent 73fad25e
No related branches found
No related tags found
1 merge request!2205rewrite DoubleSpinBox; use DoubleSpinBox for intensity; simplify RealLimits (#870)
......@@ -22,15 +22,17 @@
namespace {
QString toString(double val, int decimal_points = 4)
QString toString(double val, int decimal_points = 4) // TODO merge with other toString fcts
{
if (val == 0)
return "0";
QString result = (val >= 1000 || val < 0.1) ? QString::number(val, 'e', decimal_points)
QString result = (val >= 10000 || val < 0.1) ? QString::number(val, 'e', decimal_points)
: QString::number(val, 'f', decimal_points);
return result.replace(QRegularExpression("(\\.?0+)?((e[\\+|-])(0+)?([1-9].*))?$"), "\\3\\5");
// suppress ".0" in mantissa; normalize exponent
return result.replace(QRegularExpression("(\\.?0+)?((e)([\\+]?)([-]?)(0*)([1-9].*))?$"),
"\\3\\5\\7");
}
} // namespace
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment