Skip to content

Commit

Permalink
qgsDoubleToString: Don't remove trailing zeros when integer
Browse files Browse the repository at this point in the history
+ added testcase

Fix #12947
  • Loading branch information
m-kuhn committed Jun 12, 2015
1 parent 426465d commit ac38b21
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/core/qgis.h
Expand Up @@ -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 );
}

//
Expand Down
10 changes: 10 additions & 0 deletions tests/src/core/testqgis.cpp
Expand Up @@ -35,6 +35,7 @@ class TestQGis : public QObject

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

private:
QString mReport;
Expand Down Expand Up @@ -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.