Skip to content

Commit 42c2061

Browse files
committedMay 21, 2021
[expressions] Fix evaluation of round(...) where input value is
a string containing a decimal number Fixes #36467
1 parent 7fa74b6 commit 42c2061

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed
 

‎src/core/expression/qgsexpressionfunction.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4488,7 +4488,7 @@ static QVariant fcnRound( const QVariantList &values, const QgsExpressionContext
44884488

44894489
if ( values.length() >= 1 )
44904490
{
4491-
double number = QgsExpressionUtils::getIntValue( values.at( 0 ), parent );
4491+
double number = QgsExpressionUtils::getDoubleValue( values.at( 0 ), parent );
44924492
return QVariant( qlonglong( std::round( number ) ) );
44934493
}
44944494

‎tests/src/core/testqgsexpression.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -813,6 +813,9 @@ class TestQgsExpression: public QObject
813813
QTest::newRow( "round(1234.554,2) - round down" ) << "round(1234.554,2)" << false << QVariant( 1234.55 );
814814
QTest::newRow( "round(1234.6) - round up to int" ) << "round(1234.6)" << false << QVariant( 1235 );
815815
QTest::newRow( "round(1234.4) - round down to int" ) << "round(1234.4)" << false << QVariant( 1234 );
816+
QTest::newRow( "round('1234.434', 1) - round string down to 1 decimal" ) << "round('1234.434', 1)" << false << QVariant( 1234.4 );
817+
QTest::newRow( "round('1234.434') - round string down to int" ) << "round('1234.434')" << false << QVariant( 1234 );
818+
QTest::newRow( "round('not number') - round not a number" ) << "round('not number')" << true << QVariant();
816819
QTest::newRow( "max(1)" ) << "max(1)" << false << QVariant( 1. );
817820
QTest::newRow( "max(1,3.5,-2.1)" ) << "max(1,3.5,-2.1)" << false << QVariant( 3.5 );
818821
QTest::newRow( "max(3.5,-2.1,1)" ) << "max(3.5,-2.1,1)" << false << QVariant( 3.5 );

0 commit comments

Comments
 (0)
Please sign in to comment.