Print integer number fraction as string of numerator and denominator
Clash Royale CLAN TAG#URR8PPP
$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:
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
$endgroup$
add a comment |
$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:
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
$endgroup$
1
$begingroup$
One quick way is to replace0
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
add a comment |
$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:
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
$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:
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
string-manipulation style number-form
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 replace0
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
add a comment |
1
$begingroup$
One quick way is to replace0
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
add a comment |
2 Answers
2
active
oldest
votes
$begingroup$
Style[ToString[#, TraditionalForm], FontFamily -> "Calibri", 20, Red] & /@
(HoldForm /@ x / HoldForm /@ y)
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
$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
add a comment |
$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]
$endgroup$
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
$begingroup$
Style[ToString[#, TraditionalForm], FontFamily -> "Calibri", 20, Red] & /@
(HoldForm /@ x / HoldForm /@ y)
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
$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
add a comment |
$begingroup$
Style[ToString[#, TraditionalForm], FontFamily -> "Calibri", 20, Red] & /@
(HoldForm /@ x / HoldForm /@ y)
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
$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
add a comment |
$begingroup$
Style[ToString[#, TraditionalForm], FontFamily -> "Calibri", 20, Red] & /@
(HoldForm /@ x / HoldForm /@ y)
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
$endgroup$
Style[ToString[#, TraditionalForm], FontFamily -> "Calibri", 20, Red] & /@
(HoldForm /@ x / HoldForm /@ y)
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
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
add a comment |
$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
add a comment |
$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]
$endgroup$
add a comment |
$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]
$endgroup$
add a comment |
$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]
$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]
answered Feb 18 at 16:49
Carl WollCarl Woll
70.1k394182
70.1k394182
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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