https://issues.qgis.org/https://issues.qgis.org/favicon.ico2013-10-17T05:49:14ZQGIS Issue TrackingQGIS Application - Bug report #8897: Results from field calculator wrong formathttps://issues.qgis.org/issues/8897?journal_id=457512013-10-17T05:49:14ZNathan Woodrow
<ul></ul><p>This is more of a issue with the attribute table and attribute dialog itself. The expression engine is just doing what it is asked and returning the result. It seems the field is storing the full value even though it's an int although I don't know how.</p> QGIS Application - Bug report #8897: Results from field calculator wrong formathttps://issues.qgis.org/issues/8897?journal_id=457522013-10-17T06:03:59ZAlexander Bruy
<ul></ul><p>This is obviously correct. You divide integer to real and result surprisingly will be... real. Use toint() function in such cases or don't cast integer to float before division.</p>
<p>Also when you try save float value into integer-type field, this float will be converted (if possible) to int. So all, I stress, all works correct.</p> QGIS Application - Bug report #8897: Results from field calculator wrong formathttps://issues.qgis.org/issues/8897?journal_id=457552013-10-17T06:12:09ZJonathan Moules
<ul></ul><p>Sorry Alexander, I disagree strongly.<br />Yes, mathematically the result (3.33333.) is obviously correct. However, because the output field is an integer, it cannot store anything beyond the "3". So QGIS should <strong>never</strong> say 3.33333333 in the attribute result if the output field can't handle that.</p>
<p>QGIS is doing the conversion of 3.33333 to 3 (float to int) at save time. I'm saying it should do it before it puts it into the attribute table in the first place.</p>
<p>Similarly, if the output field is set to only allow two decimal places, qgis should only show two decimal places when the result is returned.</p>
<p>To do otherwise will confuse the vast majority of users when their data "changes".</p> QGIS Application - Bug report #8897: Results from field calculator wrong formathttps://issues.qgis.org/issues/8897?journal_id=459172013-10-23T22:38:37ZMatthias Kuhn
<ul></ul><p>It's true, the expression engine produces a QVariant which can be of a variety of types.</p>
<p>And it seems these values are stored like they are returned to the local edit buffer until being committed. This affects much more than the representation in the attribute table.</p>
<p>E.g.<br />Imagine a layer with an INT field <code>a</code>, calculated to 3.6<br />If you now create a new INT field <code>b</code> by multiplying <code>a</code> with 3 and you perform this calculation on uncommitted values the result will be 10.8 (later truncated to 10). If this calculation is done on committed values, the result will be 9.</p>
<p>It should be the edit buffer or vector layer taking care of field conversion on UPDATE / INSERT operations, so also values which originate from python scripts or other sources will be converted.</p> QGIS Application - Bug report #8897: Results from field calculator wrong formathttps://issues.qgis.org/issues/8897?journal_id=528112014-06-21T11:12:51ZJürgen Fischerjef@norbit.de
<ul><li><strong>Category</strong> set to <i>Vectors</i></li></ul> QGIS Application - Bug report #8897: Results from field calculator wrong formathttps://issues.qgis.org/issues/8897?journal_id=785692017-04-30T23:09:18ZGiovanni Manghigiovanni.manghi@gmail.com
<ul><li><strong>Regression?</strong> set to <i>No</i></li><li><strong>Easy fix?</strong> set to <i>No</i></li></ul> QGIS Application - Bug report #8897: Results from field calculator wrong formathttps://issues.qgis.org/issues/8897?journal_id=880812018-03-01T11:28:56ZGiovanni Manghigiovanni.manghi@gmail.com
<ul><li><strong>Status</strong> changed from <i>Open</i> to <i>Feedback</i></li></ul><p>Please test with a recent QGIS release (2.18 or 3), if the issue/request is still valid change the affected version accordingly, if is fixed/implemented then close the ticket. Thanks!</p> QGIS Application - Bug report #8897: Results from field calculator wrong formathttps://issues.qgis.org/issues/8897?journal_id=897482018-05-16T15:49:59ZAlexander Bruy
<ul><li><strong>Resolution</strong> set to <i>fixed/implemented</i></li><li><strong>Description</strong> updated (<a href="/journals/diff/89748?detail_id=78521" title="View differences">diff</a>)</li><li><strong>Status</strong> changed from <i>Feedback</i> to <i>Closed</i></li></ul>