Bug report #14083
Adding up (+) variables in expression builder results in concatenation
|Affected QGIS version:||2.12.1||Regression?:||No|
|Operating System:||OS X El Capitan||Easy fix?:||No|
|Pull Request or Patch supplied:||No||Resolution:||invalid|
|Crashes QGIS or corrupts data:||No||Copied to github as #:||22093|
If I add up two variables using the expression builder, the two values are concatenated, instead of added up. So if A = 2091 and B = 0, I get the result of A+B = "20910" (as if I used the || operator). The other operators (-, /, *) seem to work as they should. If I add up two integers, there is no problem.
I have the latest QGIS on the Mac. Version 2.12.2 is not yet available on the Mac, so I am not sure if the bug is still present there.
#5 Updated by Nyall Dawson almost 5 years ago
- Status changed from Reopened to Closed
Wrapping the variables in to_int/to_real is the correct solution. Multiply/etc have special handling to basically have to_real forced, but that's not possible with + because it's also reused for string concatenation. Otherwise the expression '5' + '2' would incorrectly return 7 instead of 52.