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

toString special case 0

parent 0136ca45
No related branches found
No related tags found
1 merge request!2205rewrite DoubleSpinBox; use DoubleSpinBox for intensity; simplify RealLimits (#870)
...@@ -17,17 +17,20 @@ ...@@ -17,17 +17,20 @@
#include "Base/Util/StringUtil.h" #include "Base/Util/StringUtil.h"
#include "GUI/Model/Descriptor/DoubleProperty.h" #include "GUI/Model/Descriptor/DoubleProperty.h"
#include "GUI/View/Numeric/NumberUtil.h" #include "GUI/View/Numeric/NumberUtil.h"
#include <QRegularExpression>
#include <QWheelEvent> #include <QWheelEvent>
namespace { namespace {
QString toString(double val, int decimal_points = 4) QString toString(double val, int decimal_points = 4)
{ {
if (val == 0)
return "0";
QString result = (val >= 1000 || val < 0.1) ? QString::number(val, 'e', decimal_points) QString result = (val >= 1000 || val < 0.1) ? QString::number(val, 'e', decimal_points)
: QString::number(val, 'f', decimal_points); : QString::number(val, 'f', decimal_points);
return result.replace(QRegularExpression("(\\.?0+)?((e{1}[\\+|-]{1})(0+)?([1-9]{1}.*))?$"), return result.replace(QRegularExpression("(\\.?0+)?((e[\\+|-])(0+)?([1-9].*))?$"), "\\3\\5");
"\\3\\5");
} }
} // namespace } // 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