Convert decimal to percentage value












3














How can I convert a given decimal into the respective percentage value with a certain amount of positions q after the comma? The percentage should be rounded with respect to q+1.



For example, I am looking for something like




percentage[position after the comma]{given decimal}




that produces:



percentage[positions-after-comma = 2]{0.12123456}: 12.12% 
percentage[positions-after-comma = 4]{0.12123456}: 12.1235%
percentage[positions-after-comma = 4]{2.12123456}: 212.1235%
percentage[positions-after-comma = 1]{0.6789}: 67.9%
percentage[positions-after-comma = 5]{0.6789}: 67.89000%









share|improve this question





























    3














    How can I convert a given decimal into the respective percentage value with a certain amount of positions q after the comma? The percentage should be rounded with respect to q+1.



    For example, I am looking for something like




    percentage[position after the comma]{given decimal}




    that produces:



    percentage[positions-after-comma = 2]{0.12123456}: 12.12% 
    percentage[positions-after-comma = 4]{0.12123456}: 12.1235%
    percentage[positions-after-comma = 4]{2.12123456}: 212.1235%
    percentage[positions-after-comma = 1]{0.6789}: 67.9%
    percentage[positions-after-comma = 5]{0.6789}: 67.89000%









    share|improve this question



























      3












      3








      3







      How can I convert a given decimal into the respective percentage value with a certain amount of positions q after the comma? The percentage should be rounded with respect to q+1.



      For example, I am looking for something like




      percentage[position after the comma]{given decimal}




      that produces:



      percentage[positions-after-comma = 2]{0.12123456}: 12.12% 
      percentage[positions-after-comma = 4]{0.12123456}: 12.1235%
      percentage[positions-after-comma = 4]{2.12123456}: 212.1235%
      percentage[positions-after-comma = 1]{0.6789}: 67.9%
      percentage[positions-after-comma = 5]{0.6789}: 67.89000%









      share|improve this question















      How can I convert a given decimal into the respective percentage value with a certain amount of positions q after the comma? The percentage should be rounded with respect to q+1.



      For example, I am looking for something like




      percentage[position after the comma]{given decimal}




      that produces:



      percentage[positions-after-comma = 2]{0.12123456}: 12.12% 
      percentage[positions-after-comma = 4]{0.12123456}: 12.1235%
      percentage[positions-after-comma = 4]{2.12123456}: 212.1235%
      percentage[positions-after-comma = 1]{0.6789}: 67.9%
      percentage[positions-after-comma = 5]{0.6789}: 67.89000%






      decimal-number percentage






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited yesterday

























      asked yesterday









      BJPrim

      476




      476






















          2 Answers
          2






          active

          oldest

          votes


















          5














          You can use the siunitx package:



          documentclass{article}

          usepackage{siunitx}

          newcommandpercentage[2][round-precision = 2]{% default precision: 2
          SI[round-mode = places,
          scientific-notation = fixed, fixed-exponent = 0,
          output-decimal-marker={.}, #1]{#2e2}{percent}%
          }

          begin{document}

          percentage{0.123456} % -> 12.35 %
          percentage[round-precision = 3]{0.123456} % -> 12.345 %

          end{document}





          share|improve this answer










          New contributor




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


























            4














            Your values looks wrong. But beside this:



            documentclass{article}
            usepackage{xfp,xparse}
            ExplSyntaxOn
            int_new:Nl_bjprim_round_int
            keys_define:nn {bjprim}
            {
            positions-after-comma .int_set:N = l_bjprim_round_int
            }

            NewDocumentCommandpercentage { O{} m }
            {
            keys_set:nn {bjprim}{positions-after-comma=2,#1}
            fpeval{round(#2*100,l_bjprim_round_int)}%
            }
            ExplSyntaxOff
            begin{document}


            percentage[positions-after-comma = 2]{0.123456}: 12.12%

            percentage[positions-after-comma = 4]{0.123456}: 12.1235%

            percentage[positions-after-comma = 4]{2.123456}: 212.1235%

            percentage[positions-after-comma = 1]{0.6789}: 67.9%

            percentage[positions-after-comma = 5]{0.6789}: 67.89000%

            end{document}


            If you really want to fill up with zeros you could round with siunitx:



            documentclass{article}
            usepackage{xfp,xparse,siunitx}
            ExplSyntaxOn
            int_new:Nl_bjprim_round_int
            keys_define:nn {bjprim}
            {
            positions-after-comma .int_set:N = l_bjprim_round_int
            }

            NewDocumentCommandpercentage { O{} m }
            {
            keys_set:nn {bjprim}{positions-after-comma=2,#1}
            num[round-mode = places,round-precision=l_bjprim_round_int]{fpeval{#2*100}}%
            }
            ExplSyntaxOff
            begin{document}


            percentage[positions-after-comma = 2]{0.123456}: 12.12%

            percentage[positions-after-comma = 4]{0.123456}: 12.1235%

            percentage[positions-after-comma = 4]{2.123456}: 212.1235%

            percentage[positions-after-comma = 1]{0.6789}: 67.9%

            percentage[positions-after-comma = 5]{0.6789}: 67.89000%

            end{document}


            enter image description here






            share|improve this answer























            • This way the optional argument is actually mandatory.
              – egreg
              yesterday










            • @egreg thanks, I changed to O{}.
              – Ulrike Fischer
              yesterday










            • I am struggling to get your code running. It says: "File `xfp.sty' not found." I am working with Overleaf, can it be that this package is not supported?
              – BJPrim
              yesterday










            • That's not what I meant; if you use percentage{<number>}, the previous value is used, which may or may not be desired.
              – egreg
              yesterday






            • 1




              You can remove xfp and replace fpeval by fp_eval:n.
              – Ulrike Fischer
              yesterday











            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
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f468597%2fconvert-decimal-to-percentage-value%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









            5














            You can use the siunitx package:



            documentclass{article}

            usepackage{siunitx}

            newcommandpercentage[2][round-precision = 2]{% default precision: 2
            SI[round-mode = places,
            scientific-notation = fixed, fixed-exponent = 0,
            output-decimal-marker={.}, #1]{#2e2}{percent}%
            }

            begin{document}

            percentage{0.123456} % -> 12.35 %
            percentage[round-precision = 3]{0.123456} % -> 12.345 %

            end{document}





            share|improve this answer










            New contributor




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























              5














              You can use the siunitx package:



              documentclass{article}

              usepackage{siunitx}

              newcommandpercentage[2][round-precision = 2]{% default precision: 2
              SI[round-mode = places,
              scientific-notation = fixed, fixed-exponent = 0,
              output-decimal-marker={.}, #1]{#2e2}{percent}%
              }

              begin{document}

              percentage{0.123456} % -> 12.35 %
              percentage[round-precision = 3]{0.123456} % -> 12.345 %

              end{document}





              share|improve this answer










              New contributor




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





















                5












                5








                5






                You can use the siunitx package:



                documentclass{article}

                usepackage{siunitx}

                newcommandpercentage[2][round-precision = 2]{% default precision: 2
                SI[round-mode = places,
                scientific-notation = fixed, fixed-exponent = 0,
                output-decimal-marker={.}, #1]{#2e2}{percent}%
                }

                begin{document}

                percentage{0.123456} % -> 12.35 %
                percentage[round-precision = 3]{0.123456} % -> 12.345 %

                end{document}





                share|improve this answer










                New contributor




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









                You can use the siunitx package:



                documentclass{article}

                usepackage{siunitx}

                newcommandpercentage[2][round-precision = 2]{% default precision: 2
                SI[round-mode = places,
                scientific-notation = fixed, fixed-exponent = 0,
                output-decimal-marker={.}, #1]{#2e2}{percent}%
                }

                begin{document}

                percentage{0.123456} % -> 12.35 %
                percentage[round-precision = 3]{0.123456} % -> 12.345 %

                end{document}






                share|improve this answer










                New contributor




                zetaeffe 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 answer



                share|improve this answer








                edited yesterday





















                New contributor




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









                answered yesterday









                zetaeffe

                1515




                1515




                New contributor




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





                New contributor





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






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























                    4














                    Your values looks wrong. But beside this:



                    documentclass{article}
                    usepackage{xfp,xparse}
                    ExplSyntaxOn
                    int_new:Nl_bjprim_round_int
                    keys_define:nn {bjprim}
                    {
                    positions-after-comma .int_set:N = l_bjprim_round_int
                    }

                    NewDocumentCommandpercentage { O{} m }
                    {
                    keys_set:nn {bjprim}{positions-after-comma=2,#1}
                    fpeval{round(#2*100,l_bjprim_round_int)}%
                    }
                    ExplSyntaxOff
                    begin{document}


                    percentage[positions-after-comma = 2]{0.123456}: 12.12%

                    percentage[positions-after-comma = 4]{0.123456}: 12.1235%

                    percentage[positions-after-comma = 4]{2.123456}: 212.1235%

                    percentage[positions-after-comma = 1]{0.6789}: 67.9%

                    percentage[positions-after-comma = 5]{0.6789}: 67.89000%

                    end{document}


                    If you really want to fill up with zeros you could round with siunitx:



                    documentclass{article}
                    usepackage{xfp,xparse,siunitx}
                    ExplSyntaxOn
                    int_new:Nl_bjprim_round_int
                    keys_define:nn {bjprim}
                    {
                    positions-after-comma .int_set:N = l_bjprim_round_int
                    }

                    NewDocumentCommandpercentage { O{} m }
                    {
                    keys_set:nn {bjprim}{positions-after-comma=2,#1}
                    num[round-mode = places,round-precision=l_bjprim_round_int]{fpeval{#2*100}}%
                    }
                    ExplSyntaxOff
                    begin{document}


                    percentage[positions-after-comma = 2]{0.123456}: 12.12%

                    percentage[positions-after-comma = 4]{0.123456}: 12.1235%

                    percentage[positions-after-comma = 4]{2.123456}: 212.1235%

                    percentage[positions-after-comma = 1]{0.6789}: 67.9%

                    percentage[positions-after-comma = 5]{0.6789}: 67.89000%

                    end{document}


                    enter image description here






                    share|improve this answer























                    • This way the optional argument is actually mandatory.
                      – egreg
                      yesterday










                    • @egreg thanks, I changed to O{}.
                      – Ulrike Fischer
                      yesterday










                    • I am struggling to get your code running. It says: "File `xfp.sty' not found." I am working with Overleaf, can it be that this package is not supported?
                      – BJPrim
                      yesterday










                    • That's not what I meant; if you use percentage{<number>}, the previous value is used, which may or may not be desired.
                      – egreg
                      yesterday






                    • 1




                      You can remove xfp and replace fpeval by fp_eval:n.
                      – Ulrike Fischer
                      yesterday
















                    4














                    Your values looks wrong. But beside this:



                    documentclass{article}
                    usepackage{xfp,xparse}
                    ExplSyntaxOn
                    int_new:Nl_bjprim_round_int
                    keys_define:nn {bjprim}
                    {
                    positions-after-comma .int_set:N = l_bjprim_round_int
                    }

                    NewDocumentCommandpercentage { O{} m }
                    {
                    keys_set:nn {bjprim}{positions-after-comma=2,#1}
                    fpeval{round(#2*100,l_bjprim_round_int)}%
                    }
                    ExplSyntaxOff
                    begin{document}


                    percentage[positions-after-comma = 2]{0.123456}: 12.12%

                    percentage[positions-after-comma = 4]{0.123456}: 12.1235%

                    percentage[positions-after-comma = 4]{2.123456}: 212.1235%

                    percentage[positions-after-comma = 1]{0.6789}: 67.9%

                    percentage[positions-after-comma = 5]{0.6789}: 67.89000%

                    end{document}


                    If you really want to fill up with zeros you could round with siunitx:



                    documentclass{article}
                    usepackage{xfp,xparse,siunitx}
                    ExplSyntaxOn
                    int_new:Nl_bjprim_round_int
                    keys_define:nn {bjprim}
                    {
                    positions-after-comma .int_set:N = l_bjprim_round_int
                    }

                    NewDocumentCommandpercentage { O{} m }
                    {
                    keys_set:nn {bjprim}{positions-after-comma=2,#1}
                    num[round-mode = places,round-precision=l_bjprim_round_int]{fpeval{#2*100}}%
                    }
                    ExplSyntaxOff
                    begin{document}


                    percentage[positions-after-comma = 2]{0.123456}: 12.12%

                    percentage[positions-after-comma = 4]{0.123456}: 12.1235%

                    percentage[positions-after-comma = 4]{2.123456}: 212.1235%

                    percentage[positions-after-comma = 1]{0.6789}: 67.9%

                    percentage[positions-after-comma = 5]{0.6789}: 67.89000%

                    end{document}


                    enter image description here






                    share|improve this answer























                    • This way the optional argument is actually mandatory.
                      – egreg
                      yesterday










                    • @egreg thanks, I changed to O{}.
                      – Ulrike Fischer
                      yesterday










                    • I am struggling to get your code running. It says: "File `xfp.sty' not found." I am working with Overleaf, can it be that this package is not supported?
                      – BJPrim
                      yesterday










                    • That's not what I meant; if you use percentage{<number>}, the previous value is used, which may or may not be desired.
                      – egreg
                      yesterday






                    • 1




                      You can remove xfp and replace fpeval by fp_eval:n.
                      – Ulrike Fischer
                      yesterday














                    4












                    4








                    4






                    Your values looks wrong. But beside this:



                    documentclass{article}
                    usepackage{xfp,xparse}
                    ExplSyntaxOn
                    int_new:Nl_bjprim_round_int
                    keys_define:nn {bjprim}
                    {
                    positions-after-comma .int_set:N = l_bjprim_round_int
                    }

                    NewDocumentCommandpercentage { O{} m }
                    {
                    keys_set:nn {bjprim}{positions-after-comma=2,#1}
                    fpeval{round(#2*100,l_bjprim_round_int)}%
                    }
                    ExplSyntaxOff
                    begin{document}


                    percentage[positions-after-comma = 2]{0.123456}: 12.12%

                    percentage[positions-after-comma = 4]{0.123456}: 12.1235%

                    percentage[positions-after-comma = 4]{2.123456}: 212.1235%

                    percentage[positions-after-comma = 1]{0.6789}: 67.9%

                    percentage[positions-after-comma = 5]{0.6789}: 67.89000%

                    end{document}


                    If you really want to fill up with zeros you could round with siunitx:



                    documentclass{article}
                    usepackage{xfp,xparse,siunitx}
                    ExplSyntaxOn
                    int_new:Nl_bjprim_round_int
                    keys_define:nn {bjprim}
                    {
                    positions-after-comma .int_set:N = l_bjprim_round_int
                    }

                    NewDocumentCommandpercentage { O{} m }
                    {
                    keys_set:nn {bjprim}{positions-after-comma=2,#1}
                    num[round-mode = places,round-precision=l_bjprim_round_int]{fpeval{#2*100}}%
                    }
                    ExplSyntaxOff
                    begin{document}


                    percentage[positions-after-comma = 2]{0.123456}: 12.12%

                    percentage[positions-after-comma = 4]{0.123456}: 12.1235%

                    percentage[positions-after-comma = 4]{2.123456}: 212.1235%

                    percentage[positions-after-comma = 1]{0.6789}: 67.9%

                    percentage[positions-after-comma = 5]{0.6789}: 67.89000%

                    end{document}


                    enter image description here






                    share|improve this answer














                    Your values looks wrong. But beside this:



                    documentclass{article}
                    usepackage{xfp,xparse}
                    ExplSyntaxOn
                    int_new:Nl_bjprim_round_int
                    keys_define:nn {bjprim}
                    {
                    positions-after-comma .int_set:N = l_bjprim_round_int
                    }

                    NewDocumentCommandpercentage { O{} m }
                    {
                    keys_set:nn {bjprim}{positions-after-comma=2,#1}
                    fpeval{round(#2*100,l_bjprim_round_int)}%
                    }
                    ExplSyntaxOff
                    begin{document}


                    percentage[positions-after-comma = 2]{0.123456}: 12.12%

                    percentage[positions-after-comma = 4]{0.123456}: 12.1235%

                    percentage[positions-after-comma = 4]{2.123456}: 212.1235%

                    percentage[positions-after-comma = 1]{0.6789}: 67.9%

                    percentage[positions-after-comma = 5]{0.6789}: 67.89000%

                    end{document}


                    If you really want to fill up with zeros you could round with siunitx:



                    documentclass{article}
                    usepackage{xfp,xparse,siunitx}
                    ExplSyntaxOn
                    int_new:Nl_bjprim_round_int
                    keys_define:nn {bjprim}
                    {
                    positions-after-comma .int_set:N = l_bjprim_round_int
                    }

                    NewDocumentCommandpercentage { O{} m }
                    {
                    keys_set:nn {bjprim}{positions-after-comma=2,#1}
                    num[round-mode = places,round-precision=l_bjprim_round_int]{fpeval{#2*100}}%
                    }
                    ExplSyntaxOff
                    begin{document}


                    percentage[positions-after-comma = 2]{0.123456}: 12.12%

                    percentage[positions-after-comma = 4]{0.123456}: 12.1235%

                    percentage[positions-after-comma = 4]{2.123456}: 212.1235%

                    percentage[positions-after-comma = 1]{0.6789}: 67.9%

                    percentage[positions-after-comma = 5]{0.6789}: 67.89000%

                    end{document}


                    enter image description here







                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited yesterday

























                    answered yesterday









                    Ulrike Fischer

                    187k7291670




                    187k7291670












                    • This way the optional argument is actually mandatory.
                      – egreg
                      yesterday










                    • @egreg thanks, I changed to O{}.
                      – Ulrike Fischer
                      yesterday










                    • I am struggling to get your code running. It says: "File `xfp.sty' not found." I am working with Overleaf, can it be that this package is not supported?
                      – BJPrim
                      yesterday










                    • That's not what I meant; if you use percentage{<number>}, the previous value is used, which may or may not be desired.
                      – egreg
                      yesterday






                    • 1




                      You can remove xfp and replace fpeval by fp_eval:n.
                      – Ulrike Fischer
                      yesterday


















                    • This way the optional argument is actually mandatory.
                      – egreg
                      yesterday










                    • @egreg thanks, I changed to O{}.
                      – Ulrike Fischer
                      yesterday










                    • I am struggling to get your code running. It says: "File `xfp.sty' not found." I am working with Overleaf, can it be that this package is not supported?
                      – BJPrim
                      yesterday










                    • That's not what I meant; if you use percentage{<number>}, the previous value is used, which may or may not be desired.
                      – egreg
                      yesterday






                    • 1




                      You can remove xfp and replace fpeval by fp_eval:n.
                      – Ulrike Fischer
                      yesterday
















                    This way the optional argument is actually mandatory.
                    – egreg
                    yesterday




                    This way the optional argument is actually mandatory.
                    – egreg
                    yesterday












                    @egreg thanks, I changed to O{}.
                    – Ulrike Fischer
                    yesterday




                    @egreg thanks, I changed to O{}.
                    – Ulrike Fischer
                    yesterday












                    I am struggling to get your code running. It says: "File `xfp.sty' not found." I am working with Overleaf, can it be that this package is not supported?
                    – BJPrim
                    yesterday




                    I am struggling to get your code running. It says: "File `xfp.sty' not found." I am working with Overleaf, can it be that this package is not supported?
                    – BJPrim
                    yesterday












                    That's not what I meant; if you use percentage{<number>}, the previous value is used, which may or may not be desired.
                    – egreg
                    yesterday




                    That's not what I meant; if you use percentage{<number>}, the previous value is used, which may or may not be desired.
                    – egreg
                    yesterday




                    1




                    1




                    You can remove xfp and replace fpeval by fp_eval:n.
                    – Ulrike Fischer
                    yesterday




                    You can remove xfp and replace fpeval by fp_eval:n.
                    – Ulrike Fischer
                    yesterday


















                    draft saved

                    draft discarded




















































                    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%2f468597%2fconvert-decimal-to-percentage-value%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

                    Mario Kart Wii

                    The Binding of Isaac: Rebirth/Afterbirth

                    What does “Dominus providebit” mean?