Skip to content

Commit 2579151

Browse files
committed
[expression] fix format_number() not adding group separators regression
1 parent a195a46 commit 2579151

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

src/core/expression/qgsexpressionfunction.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3072,7 +3072,9 @@ static QVariant fcnFormatNumber( const QVariantList &values, const QgsExpression
30723072
parent->setEvalErrorString( QObject::tr( "Number of places must be positive" ) );
30733073
return QVariant();
30743074
}
3075-
return QStringLiteral( "%L1" ).arg( value, 0, 'f', places );
3075+
QLocale locale = QLocale();
3076+
locale.setNumberOptions( locale.numberOptions() &= ~QLocale::NumberOption::OmitGroupSeparator );
3077+
return locale.toString( value, 'f', places );
30763078
}
30773079

30783080
static QVariant fcnFormatDate( const QVariantList &values, const QgsExpressionContext *, QgsExpression *parent, const QgsExpressionNodeFunction * )

tests/src/core/testqgsexpression.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,6 +1011,10 @@ class TestQgsExpression: public QObject
10111011
QTest::newRow( "flip_coordinates point" ) << "geom_to_wkt(flip_coordinates(geom_from_wkt('POINT(1 2)')))" << false << QVariant( "Point (2 1)" );
10121012

10131013
// string functions
1014+
QTest::newRow( "format_number" ) << "format_number(1999.567,2)" << false << QVariant( "1,999.57" );
1015+
QTest::newRow( "format_number large" ) << "format_number(9000000.0,0)" << false << QVariant( "9,000,000" );
1016+
QTest::newRow( "format_number many decimals" ) << "format_number(123.45600,4)" << false << QVariant( "123.4560" );
1017+
QTest::newRow( "format_number no decimals" ) << "format_number(1999.567,0)" << false << QVariant( "2,000" );
10141018
QTest::newRow( "lower" ) << "lower('HeLLo')" << false << QVariant( "hello" );
10151019
QTest::newRow( "upper" ) << "upper('HeLLo')" << false << QVariant( "HELLO" );
10161020
QTest::newRow( "length" ) << "length('HeLLo')" << false << QVariant( 5 );

0 commit comments

Comments
 (0)