Skip to content
Permalink
Browse files

qgsDoubleToString: Don't remove trailing zeros when integer

+ added testcase

Fix #12947
  • Loading branch information
m-kuhn committed Jun 12, 2015
1 parent 426465d commit ac38b213802919d652b062e65bd96c37c9e199ab
Showing with 14 additions and 1 deletion.
  1. +4 −1 src/core/qgis.h
  2. +10 −0 tests/src/core/testqgis.cpp
@@ -338,7 +338,10 @@ inline void ( *cast_to_fptr( void *p ) )()
//
inline QString qgsDoubleToString( const double &a, const int &precision = 17 )
{
return QString::number( a, 'f', precision ).remove( QRegExp( "\\.?0+$" ) );
if ( precision )
return QString::number( a, 'f', precision ).remove( QRegExp( "\\.?0+$" ) );
else
return QString::number( a, 'f', precision );
}

//
@@ -35,6 +35,7 @@ class TestQGis : public QObject

void permissiveToDouble();
void permissiveToInt();
void doubleToString();

private:
QString mReport;
@@ -119,5 +120,14 @@ void TestQGis::permissiveToInt()
QCOMPARE( result, 1000 );
}

void TestQGis::doubleToString()
{
QString result = qgsDoubleToString( 5.6783212, 5 );
QVERIFY( result == "5.67832" );
result = qgsDoubleToString( 5.3456789, 5 );
QVERIFY( result == "5.34568" );
result = qgsDoubleToString( 12000, 0 );
QVERIFY( result == "12000" );
}
QTEST_MAIN( TestQGis )
#include "testqgis.moc"

0 comments on commit ac38b21

Please sign in to comment.
You can’t perform that action at this time.