[Qgis-user] Field calculator QGIS2.4 division error
Nathan Woodrow
madmanwoo at gmail.com
Sat Aug 23 03:53:35 PDT 2014
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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-user/attachments/20140823/e412e99d/attachment.html>
More information about the Qgis-user
mailing list