Skip to content

Commit

Permalink
fix #3606
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@15706 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
jef committed Apr 15, 2011
1 parent cbe4ee9 commit 9fec25b
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/app/qgsfieldcalculator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "qgssearchstring.h"
#include "qgsvectordataprovider.h"
#include "qgsvectorlayer.h"

#include <QMessageBox>

QgsFieldCalculator::QgsFieldCalculator( QgsVectorLayer* vl )
Expand Down Expand Up @@ -192,7 +193,24 @@ void QgsFieldCalculator::accept()
}
else if ( value.isNumeric() )
{
mVectorLayer->changeAttributeValue( feature.id(), mAttributeId, value.number(), false );
const QgsField &f = mVectorLayer->pendingFields()[ mAttributeId ];
QVariant v;

if ( f.type() == QVariant::Double && f.precision() > 0 )
{
v = QString::number( value.number(), 'g', f.precision() );
}
else if ( f.type() == QVariant::Double && f.precision() > 0 && f.precision() == 0 )
{
v = QString::number( qRound( value.number() ) );
}
else
{
v = value.number();
}

v.convert( f.type() );
mVectorLayer->changeAttributeValue( feature.id(), mAttributeId, v, false );
}
else if ( value.isNull() )
{
Expand Down

0 comments on commit 9fec25b

Please sign in to comment.