4
$\begingroup$

Writing:

"x =" <> ToString[1/2]

I get:

enter image description here

and even if I tried in the forum I could not find a way to get rid of this problem, namely to obtain:

enter image description here

or better still:

enter image description here

Thank you!


Last formatting problem. Writing:

"x =" TextForm[1/2 q (l - 2 \[Xi])]

I get:

enter image description here

where the outer bracket is completely useless. Is it possible to remove it?

$\endgroup$
2
  • $\begingroup$ What are you looking to get? $\endgroup$ Feb 11, 2018 at 10:12
  • $\begingroup$ Try "x =" TextForm[1/2] $\endgroup$ Feb 11, 2018 at 10:17

2 Answers 2

9
$\begingroup$
"x = " <> ToString[1 / 2, StandardForm]  (* or *)
Row[{"x = ", StandardForm[1/2]}]

enter image description here

"x =" <> ToString[1/2 q (l - 2 \[Xi]), StandardForm] (* or *)
Row[{"x =", StandardForm[1/2 q (l - 2 \[Xi])]}]

enter image description here

You can use TraditionalForm in place of StandardForm above to get similar outputs.

$\endgroup$
1
  • $\begingroup$ @TeM, my pleasure. Thank you for the accept. $\endgroup$
    – kglr
    Feb 11, 2018 at 10:58
2
$\begingroup$

Something like ToString["x =" TextForm[1/2]] produces a 3 string with text formatted as necessary, if that's what you are looking for.

$\endgroup$
1
  • $\begingroup$ Please note that the output is text and it's poorly formatted i.e. division is made with "-" placed between strings with 1 and 2. $\endgroup$ Feb 11, 2018 at 10:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.