mirror of
https://git.salome-platform.org/gitpub/modules/geom.git
synced 2025-01-05 22:30:34 +05:00
Improve double values to string convertor to perform smart rounding of values.
This commit is contained in:
parent
6ceddcd35e
commit
09e9d9d991
@ -29,6 +29,7 @@
|
|||||||
#include "DlgRef_SpinBox.h"
|
#include "DlgRef_SpinBox.h"
|
||||||
|
|
||||||
#include <qvalidator.h>
|
#include <qvalidator.h>
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
//=================================================================================
|
//=================================================================================
|
||||||
// class : DlgRef_SpinBox()
|
// 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)
|
QString DlgRef_SpinBox::PrintDoubleValue (double theValue, int thePrecision)
|
||||||
{
|
{
|
||||||
|
const double prec = 1e-12;
|
||||||
|
|
||||||
QString aRes;
|
QString aRes;
|
||||||
aRes.setNum(theValue, 'g', thePrecision);
|
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
|
// remove trailing zeroes
|
||||||
QString delim( "." );
|
QString delim( "." );
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user