Skip to content
Permalink
Browse files
[expressions] Fix evaluation of round(...) where input value is
a string containing a decimal number

Fixes #36467
  • Loading branch information
nyalldawson committed May 21, 2021
1 parent 7fa74b6 commit 42c2061c5418bbcfa2fde8aac35486ac7fcb26b1
Showing with 4 additions and 1 deletion.
  1. +1 −1 src/core/expression/qgsexpressionfunction.cpp
  2. +3 −0 tests/src/core/testqgsexpression.cpp
@@ -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 ) ) );
}

@@ -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 );

0 comments on commit 42c2061

Please sign in to comment.