From: vsr Date: Thu, 19 Jun 2008 09:21:03 +0000 (+0000) Subject: Improve double values to string convertor to perform smart rounding of values. X-Git-Tag: V4_1_4a1~28 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=09e9d9d991d58348a873fa4d7b8fbc3809b85c4a;p=modules%2Fgeom.git Improve double values to string convertor to perform smart rounding of values. --- diff --git a/src/DlgRef/DlgRef_SpinBox.cxx b/src/DlgRef/DlgRef_SpinBox.cxx index 35bec55ba..2a595b12d 100644 --- a/src/DlgRef/DlgRef_SpinBox.cxx +++ b/src/DlgRef/DlgRef_SpinBox.cxx @@ -29,6 +29,7 @@ #include "DlgRef_SpinBox.h" #include +#include //================================================================================= // class : DlgRef_SpinBox() @@ -105,9 +106,22 @@ void DlgRef_SpinBox::RangeStepAndValidator(double min, double max,double step, QString DlgRef_SpinBox::PrintDoubleValue (double theValue, int thePrecision) { + const double prec = 1e-12; + QString aRes; aRes.setNum(theValue, 'g', thePrecision); + if ( prec > 0 ) { + int p = 0; + while ( p < thePrecision ) { + aRes.setNum( theValue, 'g', p++ ); + double v = aRes.toDouble(); + double err = fabs( theValue - v ); + if ( err > 0 && err <= prec ) + break; + } + } + // remove trailing zeroes QString delim( "." );