Bug report #6775
The values of a field created with field calculator (float) are rounded when they should have decimal places
Status: | Closed | ||
---|---|---|---|
Priority: | Severe/Regression | ||
Assignee: | Nathan Woodrow | ||
Category: | GUI | ||
Affected QGIS version: | master | Regression?: | No |
Operating System: | Linux Ubuntu | Easy fix?: | No |
Pull Request or Patch supplied: | No | Resolution: | wontfix |
Crashes QGIS or corrupts data: | No | Copied to github as #: | 15926 |
Description
I have table with two fields with the exact same values (1 through 25). Field1 is an integer and Field 2 is a float. If I create a Field 3 using the field calculator by typing Field1/25 or Field2/25 I get different results.
Field 3 = Field1/25 is populated by rounded values (the decimal places are not preserved)
Field 3 = Field2/25 has the correct values, with the respective decimal places
This doesnt happen on QGIS 1.8.
History
#1 Updated by Nathan Woodrow almost 12 years ago
- Resolution set to wontfix
- Status changed from Open to Closed
While it seems a bit strange this is the correct behavior. The expression engine in master, which is different to 1.8, works different and doesn't convert the result to decimal if both sides are integer. See https://github.com/qgis/Quantum-GIS/blob/master/src/core/qgsexpression.h#L80
Two ways around this:
Field1/25.00
or
toreal(Field1)/25
I prefer the first one as it's cleaner.
#2 Updated by Filipe Dias almost 12 years ago
I see. From the user point of view I think this is more likely to be seen as a bug, than as the correct behaviour. When I ask QGIS to "do the math" and specify that I want the result to have decimal places (float field), I expect it to do it correctly and show the decimal places without workarounds. In any case, this behaviour should be explained somewhere.