Navigation Menu

Skip to content

Commit

Permalink
[expressions] Fix evaluation of round(...) where input value is
Browse files Browse the repository at this point in the history
a string containing a decimal number

Fixes #36467
  • Loading branch information
nyalldawson committed May 21, 2021
1 parent 7fa74b6 commit 42c2061
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/core/expression/qgsexpressionfunction.cpp
Expand Up @@ -4488,7 +4488,7 @@ static QVariant fcnRound( const QVariantList &values, const QgsExpressionContext

if ( values.length() >= 1 )
{
double number = QgsExpressionUtils::getIntValue( values.at( 0 ), parent );
double number = QgsExpressionUtils::getDoubleValue( values.at( 0 ), parent );
return QVariant( qlonglong( std::round( number ) ) );
}

Expand Down
3 changes: 3 additions & 0 deletions tests/src/core/testqgsexpression.cpp
Expand Up @@ -813,6 +813,9 @@ class TestQgsExpression: public QObject
QTest::newRow( "round(1234.554,2) - round down" ) << "round(1234.554,2)" << false << QVariant( 1234.55 );
QTest::newRow( "round(1234.6) - round up to int" ) << "round(1234.6)" << false << QVariant( 1235 );
QTest::newRow( "round(1234.4) - round down to int" ) << "round(1234.4)" << false << QVariant( 1234 );
QTest::newRow( "round('1234.434', 1) - round string down to 1 decimal" ) << "round('1234.434', 1)" << false << QVariant( 1234.4 );
QTest::newRow( "round('1234.434') - round string down to int" ) << "round('1234.434')" << false << QVariant( 1234 );
QTest::newRow( "round('not number') - round not a number" ) << "round('not number')" << true << QVariant();
QTest::newRow( "max(1)" ) << "max(1)" << false << QVariant( 1. );
QTest::newRow( "max(1,3.5,-2.1)" ) << "max(1,3.5,-2.1)" << false << QVariant( 3.5 );
QTest::newRow( "max(3.5,-2.1,1)" ) << "max(3.5,-2.1,1)" << false << QVariant( 3.5 );
Expand Down

0 comments on commit 42c2061

Please sign in to comment.