Skip to content

Instantly share code, notes, and snippets.

@NathanW2
Created August 31, 2012 12:30
Show Gist options
  • Save NathanW2/3552180 to your computer and use it in GitHub Desktop.
Save NathanW2/3552180 to your computer and use it in GitHub Desktop.
diff --git a/src/core/qgsexpression.cpp b/src/core/qgsexpression.cpp
index ea6e292..12b911c 100644
--- a/src/core/qgsexpression.cpp
+++ b/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()
@@ -813,6 +820,7 @@ const QList<QgsExpression::FunctionDef> &QgsExpression::BuiltinFunctions()
<< FunctionDef( "log10", 1, fcnLog10, QObject::tr( "Math" ) )
<< FunctionDef( "log", 2, fcnLog, QObject::tr( "Math" ) )
<< FunctionDef( "round", -1, fcnRound, QObject::tr( "Math" ) )
+ << FunctionDef( "format_number", 2, fcnFormatNumber, QObject::tr( "Math" ) )
// casts
<< FunctionDef( "toint", 1, fcnToInt, QObject::tr( "Conversions" ) )
<< FunctionDef( "toreal", 1, fcnToReal, QObject::tr( "Conversions" ) )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment