]> SALOME platform Git repositories - modules/geom.git/blobdiff - src/DlgRef/DlgRef.cxx
Salome HOME
0020979: EDF 1168 GEOM: non coherence of display of decimal values
[modules/geom.git] / src / DlgRef / DlgRef.cxx
index 94c2ece074c2a78c2d15e833c673dda6dfe3fa71..9bd1c3fb3da62b1ddfbae1cf33206affa56ed60e 100644 (file)
@@ -781,12 +781,12 @@ QString DlgRef::PrintDoubleValue( double theValue, int thePrecision )
   if ( qAbs(theValue) < prec )
     return "0";
 
-  QString aRes = QLocale().toString( theValue, 'g', qAbs( thePrecision ) );
+  QString aRes = QLocale().toString( theValue, thePrecision >= 0 ? 'f' : 'g', qAbs( thePrecision ) );
 
   if ( prec > 0 ) {
     int p = 0;
     while ( p < thePrecision ) {
-      QString aRes = QLocale().toString( theValue, 'g', qAbs( p++ ) );
+      QString aRes = QLocale().toString( theValue, thePrecision >= 0 ? 'f' : 'g', qAbs( p++ ) );
       double v = aRes.toDouble();
       double err = qAbs( theValue - v );
       if ( err > 0 && err <= prec )
@@ -795,21 +795,19 @@ QString DlgRef::PrintDoubleValue( double theValue, int thePrecision )
   }
 
   // remove trailing zeroes
-  QString delim( QLocale().decimalPoint() );
 
-  int idx = aRes.lastIndexOf( delim );
-  if ( idx == -1 )
-    return aRes;
+  QRegExp expre( QString( "(%1|%2)[+-]?[0-9]+$" ).arg( QLocale().exponential().toLower(), 
+                                                      QLocale().exponential().toUpper() ) );
 
-  QString iPart = aRes.left( idx );
-  QString fPart = aRes.mid( idx + 1 );
-
-  while ( !fPart.isEmpty() && fPart.at( fPart.length() - 1 ) == '0' )
-    fPart.remove( fPart.length() - 1, 1 );
+  int idx = aRes.indexOf( expre );
+  QString aResExp = "";
+  if ( idx >= 0 ) {
+    aResExp = aRes.mid( idx );
+    aRes = aRes.left( idx );
+  }
 
-  aRes = iPart;
-  if ( !fPart.isEmpty() )
-    aRes += delim + fPart;
+  if ( aRes.contains( QLocale().decimalPoint() ) )
+    aRes.remove( QRegExp( QString( "(\\%1|0)0*$" ).arg( QLocale().decimalPoint() ) ) );
 
-  return aRes;
+  return aRes == "-0" ? QString( "0" ) : aRes + aResExp;
 }