Print integer number fraction as string of numerator and denominator

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP












3












$begingroup$


I want to convert an integer number fraction as text with a certain font, size and color:



Example:



x = 0, 2, 3, 0, 4;
y = 4, 5, 12, 10, 1;

Style[ToString[#, TraditionalForm], FontFamily -> "Calibri", 20,
Red] & /@ (x/y)


The result is:



enter image description here



I would like to see the fraction values 0/4, 2/5, 3/12, 0/1, 4/1 and not the results.










share|improve this question











$endgroup$







  • 1




    $begingroup$
    One quick way is to replace 0 with "0".
    $endgroup$
    – b.gatessucks
    Feb 18 at 10:30






  • 2




    $begingroup$
    What is allowed to be simplified? E.g. you don't complain about 3/12.
    $endgroup$
    – Kuba
    Feb 18 at 10:34










  • $begingroup$
    Closely related: mathematica.stackexchange.com/q/71938/5478
    $endgroup$
    – Kuba
    Feb 18 at 10:35










  • $begingroup$
    @Kuba: I would like to see the fraction values and not the results -> 0/4, 2/5, 3/12, 0/1, 4/1
    $endgroup$
    – lio
    Feb 18 at 10:36
















3












$begingroup$


I want to convert an integer number fraction as text with a certain font, size and color:



Example:



x = 0, 2, 3, 0, 4;
y = 4, 5, 12, 10, 1;

Style[ToString[#, TraditionalForm], FontFamily -> "Calibri", 20,
Red] & /@ (x/y)


The result is:



enter image description here



I would like to see the fraction values 0/4, 2/5, 3/12, 0/1, 4/1 and not the results.










share|improve this question











$endgroup$







  • 1




    $begingroup$
    One quick way is to replace 0 with "0".
    $endgroup$
    – b.gatessucks
    Feb 18 at 10:30






  • 2




    $begingroup$
    What is allowed to be simplified? E.g. you don't complain about 3/12.
    $endgroup$
    – Kuba
    Feb 18 at 10:34










  • $begingroup$
    Closely related: mathematica.stackexchange.com/q/71938/5478
    $endgroup$
    – Kuba
    Feb 18 at 10:35










  • $begingroup$
    @Kuba: I would like to see the fraction values and not the results -> 0/4, 2/5, 3/12, 0/1, 4/1
    $endgroup$
    – lio
    Feb 18 at 10:36














3












3








3





$begingroup$


I want to convert an integer number fraction as text with a certain font, size and color:



Example:



x = 0, 2, 3, 0, 4;
y = 4, 5, 12, 10, 1;

Style[ToString[#, TraditionalForm], FontFamily -> "Calibri", 20,
Red] & /@ (x/y)


The result is:



enter image description here



I would like to see the fraction values 0/4, 2/5, 3/12, 0/1, 4/1 and not the results.










share|improve this question











$endgroup$




I want to convert an integer number fraction as text with a certain font, size and color:



Example:



x = 0, 2, 3, 0, 4;
y = 4, 5, 12, 10, 1;

Style[ToString[#, TraditionalForm], FontFamily -> "Calibri", 20,
Red] & /@ (x/y)


The result is:



enter image description here



I would like to see the fraction values 0/4, 2/5, 3/12, 0/1, 4/1 and not the results.







string-manipulation style number-form






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Feb 18 at 10:42







lio

















asked Feb 18 at 10:26









liolio

1,140217




1,140217







  • 1




    $begingroup$
    One quick way is to replace 0 with "0".
    $endgroup$
    – b.gatessucks
    Feb 18 at 10:30






  • 2




    $begingroup$
    What is allowed to be simplified? E.g. you don't complain about 3/12.
    $endgroup$
    – Kuba
    Feb 18 at 10:34










  • $begingroup$
    Closely related: mathematica.stackexchange.com/q/71938/5478
    $endgroup$
    – Kuba
    Feb 18 at 10:35










  • $begingroup$
    @Kuba: I would like to see the fraction values and not the results -> 0/4, 2/5, 3/12, 0/1, 4/1
    $endgroup$
    – lio
    Feb 18 at 10:36













  • 1




    $begingroup$
    One quick way is to replace 0 with "0".
    $endgroup$
    – b.gatessucks
    Feb 18 at 10:30






  • 2




    $begingroup$
    What is allowed to be simplified? E.g. you don't complain about 3/12.
    $endgroup$
    – Kuba
    Feb 18 at 10:34










  • $begingroup$
    Closely related: mathematica.stackexchange.com/q/71938/5478
    $endgroup$
    – Kuba
    Feb 18 at 10:35










  • $begingroup$
    @Kuba: I would like to see the fraction values and not the results -> 0/4, 2/5, 3/12, 0/1, 4/1
    $endgroup$
    – lio
    Feb 18 at 10:36








1




1




$begingroup$
One quick way is to replace 0 with "0".
$endgroup$
– b.gatessucks
Feb 18 at 10:30




$begingroup$
One quick way is to replace 0 with "0".
$endgroup$
– b.gatessucks
Feb 18 at 10:30




2




2




$begingroup$
What is allowed to be simplified? E.g. you don't complain about 3/12.
$endgroup$
– Kuba
Feb 18 at 10:34




$begingroup$
What is allowed to be simplified? E.g. you don't complain about 3/12.
$endgroup$
– Kuba
Feb 18 at 10:34












$begingroup$
Closely related: mathematica.stackexchange.com/q/71938/5478
$endgroup$
– Kuba
Feb 18 at 10:35




$begingroup$
Closely related: mathematica.stackexchange.com/q/71938/5478
$endgroup$
– Kuba
Feb 18 at 10:35












$begingroup$
@Kuba: I would like to see the fraction values and not the results -> 0/4, 2/5, 3/12, 0/1, 4/1
$endgroup$
– lio
Feb 18 at 10:36





$begingroup$
@Kuba: I would like to see the fraction values and not the results -> 0/4, 2/5, 3/12, 0/1, 4/1
$endgroup$
– lio
Feb 18 at 10:36











2 Answers
2






active

oldest

votes


















5












$begingroup$

Style[ToString[#, TraditionalForm], FontFamily -> "Calibri", 20, Red] & /@ 
(HoldForm /@ x / HoldForm /@ y)


enter image description here



Also



Map[Style[ToString[#, TraditionalForm], FontFamily -> "Calibri", 20, Red] &, 
Inactivate[Divide[x, y]], -1] // Activate



same picture




and



style = Style[ToString[#, TraditionalForm], FontFamily -> "Calibri", 20, Red] &;
(style /@ x )/(style /@ y)



same picture




Update: You can use



MapThread[Style[Row[##, "/"], FontFamily -> "Calibri", 20, Red] &, x, y]


or



Style[ToString[#, TraditionalForm], FontFamily -> "Calibri", 20, Red] & /@ 
MapThread[Row[##, "/"] &, x, y]


to get



enter image description here






share|improve this answer











$endgroup$












  • $begingroup$
    This is perfect. Due to space problems in my 2d plot (the fractions are used as labels for certain points and are vertically too close to each other) I would be interested to use them as a string like this: 2/5.
    $endgroup$
    – lio
    Feb 18 at 10:55











  • $begingroup$
    @lio, please see the update.
    $endgroup$
    – kglr
    Feb 18 at 11:14










  • $begingroup$
    Thank you so much ...
    $endgroup$
    – lio
    Feb 18 at 11:27











  • $begingroup$
    @lio, my pleasure.
    $endgroup$
    – kglr
    Feb 18 at 11:27


















2












$begingroup$

You could create a wrapper that formats as desired:



MakeBoxes[HoldRational[n_Integer, d_Integer], StandardForm] ^:= MakeBoxes[
Style[InputForm[Divide[n, d]], FontFamily->"Calibri", FontColor->Red, 24],
StandardForm
]


Then:



x = 0, 2, 3, 0, 4;
y = 4, 5, 12, 10, 1;

MapThread[HoldRational, x, y]


enter image description here






share|improve this answer









$endgroup$












    Your Answer





    StackExchange.ifUsing("editor", function ()
    return StackExchange.using("mathjaxEditing", function ()
    StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
    StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
    );
    );
    , "mathjax-editing");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "387"
    ;
    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%2fmathematica.stackexchange.com%2fquestions%2f191743%2fprint-integer-number-fraction-as-string-of-numerator-and-denominator%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












    $begingroup$

    Style[ToString[#, TraditionalForm], FontFamily -> "Calibri", 20, Red] & /@ 
    (HoldForm /@ x / HoldForm /@ y)


    enter image description here



    Also



    Map[Style[ToString[#, TraditionalForm], FontFamily -> "Calibri", 20, Red] &, 
    Inactivate[Divide[x, y]], -1] // Activate



    same picture




    and



    style = Style[ToString[#, TraditionalForm], FontFamily -> "Calibri", 20, Red] &;
    (style /@ x )/(style /@ y)



    same picture




    Update: You can use



    MapThread[Style[Row[##, "/"], FontFamily -> "Calibri", 20, Red] &, x, y]


    or



    Style[ToString[#, TraditionalForm], FontFamily -> "Calibri", 20, Red] & /@ 
    MapThread[Row[##, "/"] &, x, y]


    to get



    enter image description here






    share|improve this answer











    $endgroup$












    • $begingroup$
      This is perfect. Due to space problems in my 2d plot (the fractions are used as labels for certain points and are vertically too close to each other) I would be interested to use them as a string like this: 2/5.
      $endgroup$
      – lio
      Feb 18 at 10:55











    • $begingroup$
      @lio, please see the update.
      $endgroup$
      – kglr
      Feb 18 at 11:14










    • $begingroup$
      Thank you so much ...
      $endgroup$
      – lio
      Feb 18 at 11:27











    • $begingroup$
      @lio, my pleasure.
      $endgroup$
      – kglr
      Feb 18 at 11:27















    5












    $begingroup$

    Style[ToString[#, TraditionalForm], FontFamily -> "Calibri", 20, Red] & /@ 
    (HoldForm /@ x / HoldForm /@ y)


    enter image description here



    Also



    Map[Style[ToString[#, TraditionalForm], FontFamily -> "Calibri", 20, Red] &, 
    Inactivate[Divide[x, y]], -1] // Activate



    same picture




    and



    style = Style[ToString[#, TraditionalForm], FontFamily -> "Calibri", 20, Red] &;
    (style /@ x )/(style /@ y)



    same picture




    Update: You can use



    MapThread[Style[Row[##, "/"], FontFamily -> "Calibri", 20, Red] &, x, y]


    or



    Style[ToString[#, TraditionalForm], FontFamily -> "Calibri", 20, Red] & /@ 
    MapThread[Row[##, "/"] &, x, y]


    to get



    enter image description here






    share|improve this answer











    $endgroup$












    • $begingroup$
      This is perfect. Due to space problems in my 2d plot (the fractions are used as labels for certain points and are vertically too close to each other) I would be interested to use them as a string like this: 2/5.
      $endgroup$
      – lio
      Feb 18 at 10:55











    • $begingroup$
      @lio, please see the update.
      $endgroup$
      – kglr
      Feb 18 at 11:14










    • $begingroup$
      Thank you so much ...
      $endgroup$
      – lio
      Feb 18 at 11:27











    • $begingroup$
      @lio, my pleasure.
      $endgroup$
      – kglr
      Feb 18 at 11:27













    5












    5








    5





    $begingroup$

    Style[ToString[#, TraditionalForm], FontFamily -> "Calibri", 20, Red] & /@ 
    (HoldForm /@ x / HoldForm /@ y)


    enter image description here



    Also



    Map[Style[ToString[#, TraditionalForm], FontFamily -> "Calibri", 20, Red] &, 
    Inactivate[Divide[x, y]], -1] // Activate



    same picture




    and



    style = Style[ToString[#, TraditionalForm], FontFamily -> "Calibri", 20, Red] &;
    (style /@ x )/(style /@ y)



    same picture




    Update: You can use



    MapThread[Style[Row[##, "/"], FontFamily -> "Calibri", 20, Red] &, x, y]


    or



    Style[ToString[#, TraditionalForm], FontFamily -> "Calibri", 20, Red] & /@ 
    MapThread[Row[##, "/"] &, x, y]


    to get



    enter image description here






    share|improve this answer











    $endgroup$



    Style[ToString[#, TraditionalForm], FontFamily -> "Calibri", 20, Red] & /@ 
    (HoldForm /@ x / HoldForm /@ y)


    enter image description here



    Also



    Map[Style[ToString[#, TraditionalForm], FontFamily -> "Calibri", 20, Red] &, 
    Inactivate[Divide[x, y]], -1] // Activate



    same picture




    and



    style = Style[ToString[#, TraditionalForm], FontFamily -> "Calibri", 20, Red] &;
    (style /@ x )/(style /@ y)



    same picture




    Update: You can use



    MapThread[Style[Row[##, "/"], FontFamily -> "Calibri", 20, Red] &, x, y]


    or



    Style[ToString[#, TraditionalForm], FontFamily -> "Calibri", 20, Red] & /@ 
    MapThread[Row[##, "/"] &, x, y]


    to get



    enter image description here







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Feb 18 at 11:22

























    answered Feb 18 at 10:38









    kglrkglr

    189k10205422




    189k10205422











    • $begingroup$
      This is perfect. Due to space problems in my 2d plot (the fractions are used as labels for certain points and are vertically too close to each other) I would be interested to use them as a string like this: 2/5.
      $endgroup$
      – lio
      Feb 18 at 10:55











    • $begingroup$
      @lio, please see the update.
      $endgroup$
      – kglr
      Feb 18 at 11:14










    • $begingroup$
      Thank you so much ...
      $endgroup$
      – lio
      Feb 18 at 11:27











    • $begingroup$
      @lio, my pleasure.
      $endgroup$
      – kglr
      Feb 18 at 11:27
















    • $begingroup$
      This is perfect. Due to space problems in my 2d plot (the fractions are used as labels for certain points and are vertically too close to each other) I would be interested to use them as a string like this: 2/5.
      $endgroup$
      – lio
      Feb 18 at 10:55











    • $begingroup$
      @lio, please see the update.
      $endgroup$
      – kglr
      Feb 18 at 11:14










    • $begingroup$
      Thank you so much ...
      $endgroup$
      – lio
      Feb 18 at 11:27











    • $begingroup$
      @lio, my pleasure.
      $endgroup$
      – kglr
      Feb 18 at 11:27















    $begingroup$
    This is perfect. Due to space problems in my 2d plot (the fractions are used as labels for certain points and are vertically too close to each other) I would be interested to use them as a string like this: 2/5.
    $endgroup$
    – lio
    Feb 18 at 10:55





    $begingroup$
    This is perfect. Due to space problems in my 2d plot (the fractions are used as labels for certain points and are vertically too close to each other) I would be interested to use them as a string like this: 2/5.
    $endgroup$
    – lio
    Feb 18 at 10:55













    $begingroup$
    @lio, please see the update.
    $endgroup$
    – kglr
    Feb 18 at 11:14




    $begingroup$
    @lio, please see the update.
    $endgroup$
    – kglr
    Feb 18 at 11:14












    $begingroup$
    Thank you so much ...
    $endgroup$
    – lio
    Feb 18 at 11:27





    $begingroup$
    Thank you so much ...
    $endgroup$
    – lio
    Feb 18 at 11:27













    $begingroup$
    @lio, my pleasure.
    $endgroup$
    – kglr
    Feb 18 at 11:27




    $begingroup$
    @lio, my pleasure.
    $endgroup$
    – kglr
    Feb 18 at 11:27











    2












    $begingroup$

    You could create a wrapper that formats as desired:



    MakeBoxes[HoldRational[n_Integer, d_Integer], StandardForm] ^:= MakeBoxes[
    Style[InputForm[Divide[n, d]], FontFamily->"Calibri", FontColor->Red, 24],
    StandardForm
    ]


    Then:



    x = 0, 2, 3, 0, 4;
    y = 4, 5, 12, 10, 1;

    MapThread[HoldRational, x, y]


    enter image description here






    share|improve this answer









    $endgroup$

















      2












      $begingroup$

      You could create a wrapper that formats as desired:



      MakeBoxes[HoldRational[n_Integer, d_Integer], StandardForm] ^:= MakeBoxes[
      Style[InputForm[Divide[n, d]], FontFamily->"Calibri", FontColor->Red, 24],
      StandardForm
      ]


      Then:



      x = 0, 2, 3, 0, 4;
      y = 4, 5, 12, 10, 1;

      MapThread[HoldRational, x, y]


      enter image description here






      share|improve this answer









      $endgroup$















        2












        2








        2





        $begingroup$

        You could create a wrapper that formats as desired:



        MakeBoxes[HoldRational[n_Integer, d_Integer], StandardForm] ^:= MakeBoxes[
        Style[InputForm[Divide[n, d]], FontFamily->"Calibri", FontColor->Red, 24],
        StandardForm
        ]


        Then:



        x = 0, 2, 3, 0, 4;
        y = 4, 5, 12, 10, 1;

        MapThread[HoldRational, x, y]


        enter image description here






        share|improve this answer









        $endgroup$



        You could create a wrapper that formats as desired:



        MakeBoxes[HoldRational[n_Integer, d_Integer], StandardForm] ^:= MakeBoxes[
        Style[InputForm[Divide[n, d]], FontFamily->"Calibri", FontColor->Red, 24],
        StandardForm
        ]


        Then:



        x = 0, 2, 3, 0, 4;
        y = 4, 5, 12, 10, 1;

        MapThread[HoldRational, x, y]


        enter image description here







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Feb 18 at 16:49









        Carl WollCarl Woll

        70.1k394182




        70.1k394182



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Mathematica 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.

            Use MathJax to format equations. MathJax reference.


            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%2fmathematica.stackexchange.com%2fquestions%2f191743%2fprint-integer-number-fraction-as-string-of-numerator-and-denominator%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

            How to check contact read email or not when send email to Individual?

            Displaying single band from multi-band raster using QGIS

            How many registers does an x86_64 CPU actually have?