[Qgis-user] Field calculator QGIS2.4 division error

Siki Zoltan siki at agt.bme.hu
Sat Aug 23 13:09:45 PDT 2014


Hi Nathan,

are you sure?
QgsExpression('100.0 * 50 / 3').evaluate()
1666.666666666667

QgsExpression('50 / 3 * 100.0').evaluate()
1600.0

Zoltan

On Sat, 23 Aug 2014, Nathan Woodrow wrote:

> Hey,
>
> There is no left to right here, / is higher order then * so both these are
> the same:
>
>>> exp = QgsExpression('100.0 * 50 / 2')
>>> exp2 = QgsExpression('50 / 2 * 100.0')
>>> exp.evaluate(), exp2.evaluate()
> (2500.0, 2500.0)
>
> What you are seeing is the QGIS expression engine doing the multiply part
> result first, which returns a float, then it will say "is the left side a
> int AND the right side a int" if that comes back as NO then it does a float
> operation.  Basically this means once one of the values in the equation is
> a float the result will come out as float.
>
> If you want to see the details on how this works you can find it here
> https://github.com/qgis/QGIS/blob/master/src/core/qgsexpression.cpp#L2093
>
> - Nathan
>
>
> On Sat, Aug 23, 2014 at 8:22 PM, ralfwessels <gis at ralf-wessels.de> wrote:
>
>> Hi
>> intereseting, didn't know the left to right rule explained by Zoltan:
>>
>> Siki Zoltan wrote
>>> 100.0 * "HC01_VC04"  /  "HC01_VC03" will give you the right result.
>>> First the multiplication is evaluated (left to right rule),...
>>
>> Learning never stops!
>> ralf
>>
>>
>>
>> --
>> View this message in context:
>> http://osgeo-org.1560.x6.nabble.com/Re-Field-calculator-QGIS2-4-division-error-tp5157715p5157980.html
>> Sent from the Quantum GIS - User mailing list archive at Nabble.com.
>> _______________________________________________
>> Qgis-user mailing list
>> Qgis-user at lists.osgeo.org
>> http://lists.osgeo.org/mailman/listinfo/qgis-user
>>
>



More information about the Qgis-user mailing list