Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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 fbfa025
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/core/qgsexpression.cpp
Expand Up @@ -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()
Expand Down Expand Up @@ -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 )
Expand Down

0 comments on commit fbfa025

Please sign in to comment.