Skip to content
Permalink
Browse files

Add format_number function to QgsExpression.

    - Add locale-aware separator for thousand separator
  • Loading branch information
NathanW2 committed Aug 31, 2012
1 parent 2ab844a commit fbfa025485369b12d1dd33f60bfa7d6802ac369d
Showing with 8 additions and 0 deletions.
  1. +8 −0 src/core/qgsexpression.cpp
@@ -792,6 +792,13 @@ static QVariant fcnScale( const QVariantList&, QgsFeature*, QgsExpression* paren
return QVariant( parent->scale() );
}

static QVariant fcnFormatNumber( const QVariantList& values, QgsFeature*, QgsExpression* parent )
{
double value = getDoubleValue( values.at(0), parent );
int places = getIntValue( values.at(1), parent );
return QString( "%L1" ).arg( value, 0, 'f', places );
}

QList<QgsExpression::FunctionDef> QgsExpression::gmBuiltinFunctions;

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

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

0 comments on commit fbfa025

Please sign in to comment.
You can’t perform that action at this time.