Problem with round function in expression, QGIS 3.4.2












2














I created a grid of rectangular polygons with the Create Grid function, from the Vector Creation group of the Processing Toolbox in QGIS 3.4.2.
The rectangles measure half a degree of longitude by half a degree of latitude.

When I want to label the polygons, I write an expression that rounds the values of latitude and longitude attributes to 2 decimal places, since the attributes created in the grid brings many decimal places.



But the round function rounds the values badly.



I know that I can create new attributes that express the coordinates with fewer decimal places and label the entities based on those attributes, but I was struck by the behavior of the function. I expected it to round to the nearest value.



Does anyone know what the problem is that the round function wrongly rounds off the decimal number?



Attached screenshots of Source Fields and the Attribute Table.



source-fields



round-expression










share|improve this question



























    2














    I created a grid of rectangular polygons with the Create Grid function, from the Vector Creation group of the Processing Toolbox in QGIS 3.4.2.
    The rectangles measure half a degree of longitude by half a degree of latitude.

    When I want to label the polygons, I write an expression that rounds the values of latitude and longitude attributes to 2 decimal places, since the attributes created in the grid brings many decimal places.



    But the round function rounds the values badly.



    I know that I can create new attributes that express the coordinates with fewer decimal places and label the entities based on those attributes, but I was struck by the behavior of the function. I expected it to round to the nearest value.



    Does anyone know what the problem is that the round function wrongly rounds off the decimal number?



    Attached screenshots of Source Fields and the Attribute Table.



    source-fields



    round-expression










    share|improve this question

























      2












      2








      2







      I created a grid of rectangular polygons with the Create Grid function, from the Vector Creation group of the Processing Toolbox in QGIS 3.4.2.
      The rectangles measure half a degree of longitude by half a degree of latitude.

      When I want to label the polygons, I write an expression that rounds the values of latitude and longitude attributes to 2 decimal places, since the attributes created in the grid brings many decimal places.



      But the round function rounds the values badly.



      I know that I can create new attributes that express the coordinates with fewer decimal places and label the entities based on those attributes, but I was struck by the behavior of the function. I expected it to round to the nearest value.



      Does anyone know what the problem is that the round function wrongly rounds off the decimal number?



      Attached screenshots of Source Fields and the Attribute Table.



      source-fields



      round-expression










      share|improve this question













      I created a grid of rectangular polygons with the Create Grid function, from the Vector Creation group of the Processing Toolbox in QGIS 3.4.2.
      The rectangles measure half a degree of longitude by half a degree of latitude.

      When I want to label the polygons, I write an expression that rounds the values of latitude and longitude attributes to 2 decimal places, since the attributes created in the grid brings many decimal places.



      But the round function rounds the values badly.



      I know that I can create new attributes that express the coordinates with fewer decimal places and label the entities based on those attributes, but I was struck by the behavior of the function. I expected it to round to the nearest value.



      Does anyone know what the problem is that the round function wrongly rounds off the decimal number?



      Attached screenshots of Source Fields and the Attribute Table.



      source-fields



      round-expression







      qgis-3.0 expression round-function






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked 4 hours ago









      Gabriel De Luca

      3487




      3487






















          1 Answer
          1






          active

          oldest

          votes


















          2














          Actually I cannot replicate the same behavior that you have. I created a grid with 0.5 degree width of latitude and longitude, and I round it to 2 decimal degree and it works fine. Then I added another column with a value of 50.49 and round it to 1 decimal and it worked as expected and I got 50.5. Here is the table with values:



          enter image description here



          enter image description here



          enter image description here



          I am not sure what was going wrong in your case. I used the exact version of QGIS 3.4.2.



          Update



          You are right. If I use negative latitude and longitude, I got strange results. I think this is a bug in QGIS 3.4.2. You should report this as a bug in QGIS 3.4.2 to the QGIS developer team here:



          enter image description here






          share|improve this answer























          • Thank you very much for your response, I am creating a new grid in a new project to find the solution, but the problem persists. However, I am realizing that the problem does not arise if I create the grid in positive latitude and longitude coordinates. Could you try it in negative coordinates (South and West)?
            – Gabriel De Luca
            3 hours ago










          • @GabrielDeLuca You are right, I updated my answer.
            – ahmadhanb
            3 hours ago










          • Thank you @ahmadhanb, I just opened this bug report.
            – Gabriel De Luca
            2 hours ago













          Your Answer








          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "79"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f306757%2fproblem-with-round-function-in-expression-qgis-3-4-2%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          2














          Actually I cannot replicate the same behavior that you have. I created a grid with 0.5 degree width of latitude and longitude, and I round it to 2 decimal degree and it works fine. Then I added another column with a value of 50.49 and round it to 1 decimal and it worked as expected and I got 50.5. Here is the table with values:



          enter image description here



          enter image description here



          enter image description here



          I am not sure what was going wrong in your case. I used the exact version of QGIS 3.4.2.



          Update



          You are right. If I use negative latitude and longitude, I got strange results. I think this is a bug in QGIS 3.4.2. You should report this as a bug in QGIS 3.4.2 to the QGIS developer team here:



          enter image description here






          share|improve this answer























          • Thank you very much for your response, I am creating a new grid in a new project to find the solution, but the problem persists. However, I am realizing that the problem does not arise if I create the grid in positive latitude and longitude coordinates. Could you try it in negative coordinates (South and West)?
            – Gabriel De Luca
            3 hours ago










          • @GabrielDeLuca You are right, I updated my answer.
            – ahmadhanb
            3 hours ago










          • Thank you @ahmadhanb, I just opened this bug report.
            – Gabriel De Luca
            2 hours ago


















          2














          Actually I cannot replicate the same behavior that you have. I created a grid with 0.5 degree width of latitude and longitude, and I round it to 2 decimal degree and it works fine. Then I added another column with a value of 50.49 and round it to 1 decimal and it worked as expected and I got 50.5. Here is the table with values:



          enter image description here



          enter image description here



          enter image description here



          I am not sure what was going wrong in your case. I used the exact version of QGIS 3.4.2.



          Update



          You are right. If I use negative latitude and longitude, I got strange results. I think this is a bug in QGIS 3.4.2. You should report this as a bug in QGIS 3.4.2 to the QGIS developer team here:



          enter image description here






          share|improve this answer























          • Thank you very much for your response, I am creating a new grid in a new project to find the solution, but the problem persists. However, I am realizing that the problem does not arise if I create the grid in positive latitude and longitude coordinates. Could you try it in negative coordinates (South and West)?
            – Gabriel De Luca
            3 hours ago










          • @GabrielDeLuca You are right, I updated my answer.
            – ahmadhanb
            3 hours ago










          • Thank you @ahmadhanb, I just opened this bug report.
            – Gabriel De Luca
            2 hours ago
















          2












          2








          2






          Actually I cannot replicate the same behavior that you have. I created a grid with 0.5 degree width of latitude and longitude, and I round it to 2 decimal degree and it works fine. Then I added another column with a value of 50.49 and round it to 1 decimal and it worked as expected and I got 50.5. Here is the table with values:



          enter image description here



          enter image description here



          enter image description here



          I am not sure what was going wrong in your case. I used the exact version of QGIS 3.4.2.



          Update



          You are right. If I use negative latitude and longitude, I got strange results. I think this is a bug in QGIS 3.4.2. You should report this as a bug in QGIS 3.4.2 to the QGIS developer team here:



          enter image description here






          share|improve this answer














          Actually I cannot replicate the same behavior that you have. I created a grid with 0.5 degree width of latitude and longitude, and I round it to 2 decimal degree and it works fine. Then I added another column with a value of 50.49 and round it to 1 decimal and it worked as expected and I got 50.5. Here is the table with values:



          enter image description here



          enter image description here



          enter image description here



          I am not sure what was going wrong in your case. I used the exact version of QGIS 3.4.2.



          Update



          You are right. If I use negative latitude and longitude, I got strange results. I think this is a bug in QGIS 3.4.2. You should report this as a bug in QGIS 3.4.2 to the QGIS developer team here:



          enter image description here







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited 3 hours ago

























          answered 4 hours ago









          ahmadhanb

          21.6k31951




          21.6k31951












          • Thank you very much for your response, I am creating a new grid in a new project to find the solution, but the problem persists. However, I am realizing that the problem does not arise if I create the grid in positive latitude and longitude coordinates. Could you try it in negative coordinates (South and West)?
            – Gabriel De Luca
            3 hours ago










          • @GabrielDeLuca You are right, I updated my answer.
            – ahmadhanb
            3 hours ago










          • Thank you @ahmadhanb, I just opened this bug report.
            – Gabriel De Luca
            2 hours ago




















          • Thank you very much for your response, I am creating a new grid in a new project to find the solution, but the problem persists. However, I am realizing that the problem does not arise if I create the grid in positive latitude and longitude coordinates. Could you try it in negative coordinates (South and West)?
            – Gabriel De Luca
            3 hours ago










          • @GabrielDeLuca You are right, I updated my answer.
            – ahmadhanb
            3 hours ago










          • Thank you @ahmadhanb, I just opened this bug report.
            – Gabriel De Luca
            2 hours ago


















          Thank you very much for your response, I am creating a new grid in a new project to find the solution, but the problem persists. However, I am realizing that the problem does not arise if I create the grid in positive latitude and longitude coordinates. Could you try it in negative coordinates (South and West)?
          – Gabriel De Luca
          3 hours ago




          Thank you very much for your response, I am creating a new grid in a new project to find the solution, but the problem persists. However, I am realizing that the problem does not arise if I create the grid in positive latitude and longitude coordinates. Could you try it in negative coordinates (South and West)?
          – Gabriel De Luca
          3 hours ago












          @GabrielDeLuca You are right, I updated my answer.
          – ahmadhanb
          3 hours ago




          @GabrielDeLuca You are right, I updated my answer.
          – ahmadhanb
          3 hours ago












          Thank you @ahmadhanb, I just opened this bug report.
          – Gabriel De Luca
          2 hours ago






          Thank you @ahmadhanb, I just opened this bug report.
          – Gabriel De Luca
          2 hours ago




















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Geographic Information Systems Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f306757%2fproblem-with-round-function-in-expression-qgis-3-4-2%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Plaza Victoria

          Puebla de Zaragoza

          Musa