Skip to content

Commit fbfa025

Browse files
committedAug 31, 2012
Add format_number function to QgsExpression.
- Add locale-aware separator for thousand separator
1 parent 2ab844a commit fbfa025

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed
 

‎src/core/qgsexpression.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -792,6 +792,13 @@ static QVariant fcnScale( const QVariantList&, QgsFeature*, QgsExpression* paren
792792
return QVariant( parent->scale() );
793793
}
794794

795+
static QVariant fcnFormatNumber( const QVariantList& values, QgsFeature*, QgsExpression* parent )
796+
{
797+
double value = getDoubleValue( values.at(0), parent );
798+
int places = getIntValue( values.at(1), parent );
799+
return QString( "%L1" ).arg( value, 0, 'f', places );
800+
}
801+
795802
QList<QgsExpression::FunctionDef> QgsExpression::gmBuiltinFunctions;
796803

797804
const QList<QgsExpression::FunctionDef> &QgsExpression::BuiltinFunctions()
@@ -847,6 +854,7 @@ const QList<QgsExpression::FunctionDef> &QgsExpression::BuiltinFunctions()
847854
<< FunctionDef( "right", 2, fcnRight, QObject::tr( "String" ) )
848855
<< FunctionDef( "rpad", 3, fcnRPad, QObject::tr( "String" ) )
849856
<< FunctionDef( "lpad", 3, fcnLPad, QObject::tr( "String" ) )
857+
<< FunctionDef( "format_number", 2, fcnFormatNumber, QObject::tr( "String" ) )
850858

851859
// geometry accessors
852860
<< FunctionDef( "xat", 1, fcnXat, QObject::tr( "Geometry" ), "", true )

0 commit comments

Comments
 (0)
Please sign in to comment.