Test of integers? Or, round the number if the first two decimal numbers are sufficiently close to 0 or 1?












4














The following is a MWE, which explains my intention.



documentclass{article}
usepackage{tikz}
usetikzlibrary{math}
begin{document}
tikzmath{
integer = 4/2; decimal = 5/3;
integerB=1/3*3;
}
$integer$ is an integer, and it should be printed as 2.
And $decimal$ is a decimal number, I would like to round it to 1.7.
Another difficulty is that $integerB$ is an integer in fact,
and should be printed as 1.
end{document}


I wonder if it is possible to test a number to determine it is an integer. Alternatively, it would also be great if it is possible to determine whether the first two decimal numbers are sufficiently close to 0 or 1.










share|improve this question









New contributor




Glenn is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

























    4














    The following is a MWE, which explains my intention.



    documentclass{article}
    usepackage{tikz}
    usetikzlibrary{math}
    begin{document}
    tikzmath{
    integer = 4/2; decimal = 5/3;
    integerB=1/3*3;
    }
    $integer$ is an integer, and it should be printed as 2.
    And $decimal$ is a decimal number, I would like to round it to 1.7.
    Another difficulty is that $integerB$ is an integer in fact,
    and should be printed as 1.
    end{document}


    I wonder if it is possible to test a number to determine it is an integer. Alternatively, it would also be great if it is possible to determine whether the first two decimal numbers are sufficiently close to 0 or 1.










    share|improve this question









    New contributor




    Glenn is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.























      4












      4








      4


      0





      The following is a MWE, which explains my intention.



      documentclass{article}
      usepackage{tikz}
      usetikzlibrary{math}
      begin{document}
      tikzmath{
      integer = 4/2; decimal = 5/3;
      integerB=1/3*3;
      }
      $integer$ is an integer, and it should be printed as 2.
      And $decimal$ is a decimal number, I would like to round it to 1.7.
      Another difficulty is that $integerB$ is an integer in fact,
      and should be printed as 1.
      end{document}


      I wonder if it is possible to test a number to determine it is an integer. Alternatively, it would also be great if it is possible to determine whether the first two decimal numbers are sufficiently close to 0 or 1.










      share|improve this question









      New contributor




      Glenn is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      The following is a MWE, which explains my intention.



      documentclass{article}
      usepackage{tikz}
      usetikzlibrary{math}
      begin{document}
      tikzmath{
      integer = 4/2; decimal = 5/3;
      integerB=1/3*3;
      }
      $integer$ is an integer, and it should be printed as 2.
      And $decimal$ is a decimal number, I would like to round it to 1.7.
      Another difficulty is that $integerB$ is an integer in fact,
      and should be printed as 1.
      end{document}


      I wonder if it is possible to test a number to determine it is an integer. Alternatively, it would also be great if it is possible to determine whether the first two decimal numbers are sufficiently close to 0 or 1.







      tables tikzmath decimal-number






      share|improve this question









      New contributor




      Glenn is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      share|improve this question









      New contributor




      Glenn is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      share|improve this question




      share|improve this question








      edited 1 hour ago









      egreg

      709k8618823164




      709k8618823164






      New contributor




      Glenn is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      asked 1 hour ago









      Glenn

      211




      211




      New contributor




      Glenn is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





      New contributor





      Glenn is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






      Glenn is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






















          2 Answers
          2






          active

          oldest

          votes


















          2














          One cannot say from its floating point representation whether the output of an arithmetic operation involving division or non rational operations is actually an integer.



          You can consider the l3fp module of expl3, available through the package xfp.



          documentclass{article}
          usepackage{xfp}

          begin{document}

          $fpeval{5/3}$ is a decimal number, I would like to round it to
          $fpeval{round(5/3,1)}$ or to $fpeval{round(5/3,2)}$

          Another difficulty is that $fpeval{(1/3)*3}$ is an integer in fact,
          and should be printed as $fpeval{round((1/3)*3,1)}$ or
          $fpeval{round((1/3)*3,2)}$.

          end{document}


          enter image description here






          share|improve this answer





























            1














            If the accuracy of your numbers is important you might consider farming that out to a computer algebra system (CAS). The sagetex package relies on the CAS Sage; the documentation can be found on CTAN right here. Documentation on Sage is found here .Sage is not part of the LaTeX distribution (it's big) so it needs to be installed on your computer or, even easier, accessed through a free Cocalc account.



            documentclass{article}
            usepackage{sagetex}
            usepackage{tikz}
            usetikzlibrary{math}
            begin{document}
            begin{sagesilent}
            a = 4/2
            b = 5/3
            c = 1/3*3
            end{sagesilent}
            $sage{a}$ is an integer, and it should be printed as $sage{a}$.
            And $sage{b}$ is not an integer. As a decimal it is approximately
            $sage{b.n(digits=6)}$. I would like to round it to $sage{b.n(digits=1)}$.
            Another difficulty is that $sage{c}$ is an integer in fact,
            and should be printed as $sage{c}$.
            end{document}


            The output, running in Cocalc, gives:
            enter image description here



            Notice that Sage interprets your numbers correctly: 4/2 is recognized as 2 and 1/3*3 is recognized as 1. It does need to know the format you want of non integers; but it recognizes that 5/3 is a fraction that can't be reduced and leaves it as a fraction. To force it into a decimal and to specify the number of digits we append .n(digits=6); the documentation is here.






            share|improve this answer





















              Your Answer








              StackExchange.ready(function() {
              var channelOptions = {
              tags: "".split(" "),
              id: "85"
              };
              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
              });


              }
              });






              Glenn is a new contributor. Be nice, and check out our Code of Conduct.










              draft saved

              draft discarded


















              StackExchange.ready(
              function () {
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f468046%2ftest-of-integers-or-round-the-number-if-the-first-two-decimal-numbers-are-suff%23new-answer', 'question_page');
              }
              );

              Post as a guest















              Required, but never shown

























              2 Answers
              2






              active

              oldest

              votes








              2 Answers
              2






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              2














              One cannot say from its floating point representation whether the output of an arithmetic operation involving division or non rational operations is actually an integer.



              You can consider the l3fp module of expl3, available through the package xfp.



              documentclass{article}
              usepackage{xfp}

              begin{document}

              $fpeval{5/3}$ is a decimal number, I would like to round it to
              $fpeval{round(5/3,1)}$ or to $fpeval{round(5/3,2)}$

              Another difficulty is that $fpeval{(1/3)*3}$ is an integer in fact,
              and should be printed as $fpeval{round((1/3)*3,1)}$ or
              $fpeval{round((1/3)*3,2)}$.

              end{document}


              enter image description here






              share|improve this answer


























                2














                One cannot say from its floating point representation whether the output of an arithmetic operation involving division or non rational operations is actually an integer.



                You can consider the l3fp module of expl3, available through the package xfp.



                documentclass{article}
                usepackage{xfp}

                begin{document}

                $fpeval{5/3}$ is a decimal number, I would like to round it to
                $fpeval{round(5/3,1)}$ or to $fpeval{round(5/3,2)}$

                Another difficulty is that $fpeval{(1/3)*3}$ is an integer in fact,
                and should be printed as $fpeval{round((1/3)*3,1)}$ or
                $fpeval{round((1/3)*3,2)}$.

                end{document}


                enter image description here






                share|improve this answer
























                  2












                  2








                  2






                  One cannot say from its floating point representation whether the output of an arithmetic operation involving division or non rational operations is actually an integer.



                  You can consider the l3fp module of expl3, available through the package xfp.



                  documentclass{article}
                  usepackage{xfp}

                  begin{document}

                  $fpeval{5/3}$ is a decimal number, I would like to round it to
                  $fpeval{round(5/3,1)}$ or to $fpeval{round(5/3,2)}$

                  Another difficulty is that $fpeval{(1/3)*3}$ is an integer in fact,
                  and should be printed as $fpeval{round((1/3)*3,1)}$ or
                  $fpeval{round((1/3)*3,2)}$.

                  end{document}


                  enter image description here






                  share|improve this answer












                  One cannot say from its floating point representation whether the output of an arithmetic operation involving division or non rational operations is actually an integer.



                  You can consider the l3fp module of expl3, available through the package xfp.



                  documentclass{article}
                  usepackage{xfp}

                  begin{document}

                  $fpeval{5/3}$ is a decimal number, I would like to round it to
                  $fpeval{round(5/3,1)}$ or to $fpeval{round(5/3,2)}$

                  Another difficulty is that $fpeval{(1/3)*3}$ is an integer in fact,
                  and should be printed as $fpeval{round((1/3)*3,1)}$ or
                  $fpeval{round((1/3)*3,2)}$.

                  end{document}


                  enter image description here







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered 1 hour ago









                  egreg

                  709k8618823164




                  709k8618823164























                      1














                      If the accuracy of your numbers is important you might consider farming that out to a computer algebra system (CAS). The sagetex package relies on the CAS Sage; the documentation can be found on CTAN right here. Documentation on Sage is found here .Sage is not part of the LaTeX distribution (it's big) so it needs to be installed on your computer or, even easier, accessed through a free Cocalc account.



                      documentclass{article}
                      usepackage{sagetex}
                      usepackage{tikz}
                      usetikzlibrary{math}
                      begin{document}
                      begin{sagesilent}
                      a = 4/2
                      b = 5/3
                      c = 1/3*3
                      end{sagesilent}
                      $sage{a}$ is an integer, and it should be printed as $sage{a}$.
                      And $sage{b}$ is not an integer. As a decimal it is approximately
                      $sage{b.n(digits=6)}$. I would like to round it to $sage{b.n(digits=1)}$.
                      Another difficulty is that $sage{c}$ is an integer in fact,
                      and should be printed as $sage{c}$.
                      end{document}


                      The output, running in Cocalc, gives:
                      enter image description here



                      Notice that Sage interprets your numbers correctly: 4/2 is recognized as 2 and 1/3*3 is recognized as 1. It does need to know the format you want of non integers; but it recognizes that 5/3 is a fraction that can't be reduced and leaves it as a fraction. To force it into a decimal and to specify the number of digits we append .n(digits=6); the documentation is here.






                      share|improve this answer


























                        1














                        If the accuracy of your numbers is important you might consider farming that out to a computer algebra system (CAS). The sagetex package relies on the CAS Sage; the documentation can be found on CTAN right here. Documentation on Sage is found here .Sage is not part of the LaTeX distribution (it's big) so it needs to be installed on your computer or, even easier, accessed through a free Cocalc account.



                        documentclass{article}
                        usepackage{sagetex}
                        usepackage{tikz}
                        usetikzlibrary{math}
                        begin{document}
                        begin{sagesilent}
                        a = 4/2
                        b = 5/3
                        c = 1/3*3
                        end{sagesilent}
                        $sage{a}$ is an integer, and it should be printed as $sage{a}$.
                        And $sage{b}$ is not an integer. As a decimal it is approximately
                        $sage{b.n(digits=6)}$. I would like to round it to $sage{b.n(digits=1)}$.
                        Another difficulty is that $sage{c}$ is an integer in fact,
                        and should be printed as $sage{c}$.
                        end{document}


                        The output, running in Cocalc, gives:
                        enter image description here



                        Notice that Sage interprets your numbers correctly: 4/2 is recognized as 2 and 1/3*3 is recognized as 1. It does need to know the format you want of non integers; but it recognizes that 5/3 is a fraction that can't be reduced and leaves it as a fraction. To force it into a decimal and to specify the number of digits we append .n(digits=6); the documentation is here.






                        share|improve this answer
























                          1












                          1








                          1






                          If the accuracy of your numbers is important you might consider farming that out to a computer algebra system (CAS). The sagetex package relies on the CAS Sage; the documentation can be found on CTAN right here. Documentation on Sage is found here .Sage is not part of the LaTeX distribution (it's big) so it needs to be installed on your computer or, even easier, accessed through a free Cocalc account.



                          documentclass{article}
                          usepackage{sagetex}
                          usepackage{tikz}
                          usetikzlibrary{math}
                          begin{document}
                          begin{sagesilent}
                          a = 4/2
                          b = 5/3
                          c = 1/3*3
                          end{sagesilent}
                          $sage{a}$ is an integer, and it should be printed as $sage{a}$.
                          And $sage{b}$ is not an integer. As a decimal it is approximately
                          $sage{b.n(digits=6)}$. I would like to round it to $sage{b.n(digits=1)}$.
                          Another difficulty is that $sage{c}$ is an integer in fact,
                          and should be printed as $sage{c}$.
                          end{document}


                          The output, running in Cocalc, gives:
                          enter image description here



                          Notice that Sage interprets your numbers correctly: 4/2 is recognized as 2 and 1/3*3 is recognized as 1. It does need to know the format you want of non integers; but it recognizes that 5/3 is a fraction that can't be reduced and leaves it as a fraction. To force it into a decimal and to specify the number of digits we append .n(digits=6); the documentation is here.






                          share|improve this answer












                          If the accuracy of your numbers is important you might consider farming that out to a computer algebra system (CAS). The sagetex package relies on the CAS Sage; the documentation can be found on CTAN right here. Documentation on Sage is found here .Sage is not part of the LaTeX distribution (it's big) so it needs to be installed on your computer or, even easier, accessed through a free Cocalc account.



                          documentclass{article}
                          usepackage{sagetex}
                          usepackage{tikz}
                          usetikzlibrary{math}
                          begin{document}
                          begin{sagesilent}
                          a = 4/2
                          b = 5/3
                          c = 1/3*3
                          end{sagesilent}
                          $sage{a}$ is an integer, and it should be printed as $sage{a}$.
                          And $sage{b}$ is not an integer. As a decimal it is approximately
                          $sage{b.n(digits=6)}$. I would like to round it to $sage{b.n(digits=1)}$.
                          Another difficulty is that $sage{c}$ is an integer in fact,
                          and should be printed as $sage{c}$.
                          end{document}


                          The output, running in Cocalc, gives:
                          enter image description here



                          Notice that Sage interprets your numbers correctly: 4/2 is recognized as 2 and 1/3*3 is recognized as 1. It does need to know the format you want of non integers; but it recognizes that 5/3 is a fraction that can't be reduced and leaves it as a fraction. To force it into a decimal and to specify the number of digits we append .n(digits=6); the documentation is here.







                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered 1 hour ago









                          DJP

                          7,04421629




                          7,04421629






















                              Glenn is a new contributor. Be nice, and check out our Code of Conduct.










                              draft saved

                              draft discarded


















                              Glenn is a new contributor. Be nice, and check out our Code of Conduct.













                              Glenn is a new contributor. Be nice, and check out our Code of Conduct.












                              Glenn is a new contributor. Be nice, and check out our Code of Conduct.
















                              Thanks for contributing an answer to TeX - LaTeX 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%2ftex.stackexchange.com%2fquestions%2f468046%2ftest-of-integers-or-round-the-number-if-the-first-two-decimal-numbers-are-suff%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

                              In PowerPoint, is there a keyboard shortcut for bulleted / numbered list?

                              How to put 3 figures in Latex with 2 figures side by side and 1 below these side by side images but in...