1

In QGIS field-calculator round() is not working in QGIS 1.8 so I try to do the following with a regex: I'd like to keep the first two places after the decimal point - where do I go wrong?

regexp_replace( tostring( "Shape_Area" / 10000 ), '(\d+\.\d{2})\d+', '\1')

enter image description here

5
  • Hi Kay, could you give a little more context about where you run this code and what the result you get, along with previous research and things you have already tried. – Matthias Kuhn May 29 '13 at 11:14
  • Matthias, I edited the original post. – Kay May 29 '13 at 12:49
  • 1
    There would be simpler ways to achieve these results using e.g. rounding functions. Or are you trying to learn regex? – underdark May 29 '13 at 13:42
  • Doesn't the FC have an 'int', 'floor', or 'ceiling' function? (Rounding is usually implemented via truncation, like int, under the hood anyway, as in int("Shape_Area" * 100 + 1/2)/100.) – whuber May 29 '13 at 16:36
  • @underdark, 1.8 doesn't support round() as I understood it.. – Kay May 29 '13 at 20:16
4

This one works for me

toint(value * 100) / 100.0
1
  • it is as simple as that - thanks! (i'm still keen to know what the error in the regex caused..) – Kay Jun 1 '13 at 17:31
0

You might try '(\d+\.\d\d)\d+', '\1')

1
  • tried this before - still get the same error.. – Kay Jun 1 '13 at 17:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.