Skip to content

Commit ac38b21

Browse files
committedJun 12, 2015
qgsDoubleToString: Don't remove trailing zeros when integer
+ added testcase Fix #12947
1 parent 426465d commit ac38b21

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed
 

‎src/core/qgis.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,10 @@ inline void ( *cast_to_fptr( void *p ) )()
338338
//
339339
inline QString qgsDoubleToString( const double &a, const int &precision = 17 )
340340
{
341-
return QString::number( a, 'f', precision ).remove( QRegExp( "\\.?0+$" ) );
341+
if ( precision )
342+
return QString::number( a, 'f', precision ).remove( QRegExp( "\\.?0+$" ) );
343+
else
344+
return QString::number( a, 'f', precision );
342345
}
343346

344347
//

‎tests/src/core/testqgis.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ class TestQGis : public QObject
3535

3636
void permissiveToDouble();
3737
void permissiveToInt();
38+
void doubleToString();
3839

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

123+
void TestQGis::doubleToString()
124+
{
125+
QString result = qgsDoubleToString( 5.6783212, 5 );
126+
QVERIFY( result == "5.67832" );
127+
result = qgsDoubleToString( 5.3456789, 5 );
128+
QVERIFY( result == "5.34568" );
129+
result = qgsDoubleToString( 12000, 0 );
130+
QVERIFY( result == "12000" );
131+
}
122132
QTEST_MAIN( TestQGis )
123133
#include "testqgis.moc"

0 commit comments

Comments
 (0)
Please sign in to comment.